I have this scenario : In SQL 2008 I run query select statement in which want to declare variable that I will use in that statement to allocate value of from subquery, and then use this variable in case expression.
Declare @GetTeamDesc NVARCHAR(100)
Select field1,field2,(subquery_getTeamDesc)as TeamDesc,field3
Now I want to use value of subqery in case when…expression.
However subqery is big and I don’t want to repeate it in case when can I do something as
I want something like this:
Set @GetTeamDesc= (Subquery_getTeamDesc)
When @GetTeamDesc like %XXX% Then
When @GetTeamDesc like %YYY% then
End as Team_Desc ,
Is this posible I am getting error:
Incorrect syntax near the keyword 'SET' at line Set @GetTeamDesc = (Subquery_getTeamDesc)