You should be able to do something like this:

USE Northwind
DECLARE @var1 nvarchar(30)
SELECT @var1 = 'Generic Name'

SELECT @var1 =
    (SELECT CompanyName
    FROM Customers
    WHERE CustomerID = 'ALFKA')

/* SELECT @var1 AS 'Company Name' This ends the example code*/
exec MyStoredProcedure2 @var1
  You'll get an error if the subquery returns more than 1 value, however if 
that is what you need I believe that cursors will handle it.
  Look up the docs on "select @local_variable" or "set @local_variable" for 
more info.  That's where I stole the example from.


At 03:57 AM 2/22/2006, you wrote:
>I've answered my own question. Between is faster by far.
>
>I was trying to get all of the records for a specific day from a large DB
>and it was taking forever even though the created (datetime) field was
>indexed. DateDiff(d, created, @datein) took waaay too long. I tried to do a
>query to get the start and end ids for the specific date to do a between but
>have no clue how to pass the date from one query to another within a SP.
>My final solution was to turn the dates into integers and compare those. Not
>great, but....
>
>If anyone knows how todo a query that uses info from another query in the
>same SP, please let me know.
>Thanks
>
>
> >I have some huge logs and I want to get specific data from them. I have 2
> >choices on how I can get all of the entries for a single day. The first
> >choice is to do a datediff between the day I want and the date in the
> >created field. The second is to do one query to get the min and max for a
> >specific date and then do a second query to get all records between these
> >two numbers.
> > Logically, the first should be faster, but is it?
> >
> >
>
>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Message: http://www.houseoffusion.com/lists.cfm/link=i:6:2438
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/6
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:6
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.6
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to