Sunday, March 11, 2012

declaring a sql query to a variable...

Hello all! After I declar a variable how would I set the result of a sql query to the variable so i can utilize it further in my stored procedure?

-Thanks,
Rich

declare @.what varchar(2)

Code Snippet

select @.what = targetColumn

from targetTable

Where testKey = 'Whatever'

-- or the SET alternative:

Code Snippet

set @.what

= ( select taretColumn

from targetTable

where testKey = 'Whatever'

)

Give a look at SET and SELECT in books online.

|||

Kent Waldrop Se07 wrote:

declare @.what varchar(2)

Code Snippet

select @.what = targetColumn

from targetTable

Where testKey = 'Whatever'

-- or the SET alternative:

Code Snippet

set @.what

= ( select taretColumn

from targetTable

where testKey = 'Whatever'

)

Give a look at SET and SELECT in books online.

Thanks! When you mentioned to have a look at SET and SELECT in books online... are the books free or do i need to purchase them?

-Thanks,
Rich
|||

Free. As a download:

http://www.microsoft.com/downloads/results.aspx?pocId=&freetext=sql%20server%20books%20online&DisplayLang=en

As a webpage:

http://msdn2.microsoft.com/en-us/library/bb545450.aspx

No comments:

Post a Comment