sql - Start with IF statement in Subquery -


i in need select rows in subquery if condition

declare @versionno varchar(30) set @versionno = 'hello' 

select (case @versionno when 'hello' (select '22','22') else (select '25','22') end)

but getting error

msg 156, level 15, state 1, line 4
incorrect syntax near keyword 'if'.

msg 156, level 15, state 1, line 4
incorrect syntax near keyword 'then'.

msg 156, level 15, state 1, line 5
incorrect syntax near keyword 'else'.

msg 102, level 15, state 1, line 5
incorrect syntax near ')'.

can me resolve this?

from answers, have changed query

declare @versionno varchar(30)     set @versionno = 'hello'     select (case @versionno when 'hello' (select '22','22') else (select '25','22') end)  

now getting error

msg 116, level 16, state 1, line 4
1 expression can specified in select list when subquery not introduced exists.

use case when:

declare @versionno varchar(30); set @versionno = 'hello';  select case when @versionno='hello' 'yes' else 'no' end somecol; 

Comments

Popular posts from this blog

hibernate - How to load global settings frequently used in application in Java -

python 3.x - Mapping specific letters onto a list of words -

objective c - Ownership modifiers with manual reference counting -