Is it possible to use a Case statement in a sql From clause using SQL 2005? For example, I’m trying something like:
SELECT Md5 FROM CASE WHEN @ClientType = 'Employee' THEN @Source = 'HR' WHEN @ClientType = 'Member' THEN @Source = 'Other' END CASE WHERE Current = 2;
Assuming SQL Server:
You would need to use dynamic SQL. Build the string and then call sp_executesql with the string.
Edit: Better yet, just use if statements to execute the appropriate statement and assign the value to a variable. You should avoid dynamic SQL if possible.