August 3, 2010 at 2:45 pm
Greetings SQL Gurus,
I have a quick question. Anyone know how, or if it is possible, to pass a case statement into a variable? lets say I have the following:
declare @myvariable
set = "case statement"
Select a, b, @myvariable as c
from mytable
anyway to set the variable = to a query with a case statement??? I know this can be done inside SSIS using the execute sql task, but how about using SSMS???
HELP!??!
Al
August 4, 2010 at 6:36 am
No, you can't do that. Not that way. A variable is just a place holder and is not resolved into TSQL on the fly. What you can do, and I don't recommend it, is use variables to create a string and then execute the string as dynamic SQL.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
August 4, 2010 at 6:53 am
This is duplicate post to one posted on T-SQL(SS2K8).
August 4, 2010 at 7:42 am
Thanks! I was hoping to avoid Dynamic SQL, but I guess it is something I am just going to have to deal with 😀 Thanks Again.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply