using ?: operation in sql server 2008
-
hi all i want to use some thing like that
set @a=@AnimalName == "Elephant"? "savannah": "unknown"
but it has an error in == how can i fix it? besides i want to use conditional ?: operation to concat some strings like bellow how i should so;ve this problem?
N'insert into TBL Values(@Val1,'+ @Condition = 1? N'val2':N'val3')+',...'
-
hi all i want to use some thing like that
set @a=@AnimalName == "Elephant"? "savannah": "unknown"
but it has an error in == how can i fix it? besides i want to use conditional ?: operation to concat some strings like bellow how i should so;ve this problem?
N'insert into TBL Values(@Val1,'+ @Condition = 1? N'val2':N'val3')+',...'
Conditionals in Transact-SQL are expressed using the CASE statement[^]. Examples in the documentation should help you construct what you need.
-
Conditionals in Transact-SQL are expressed using the CASE statement[^]. Examples in the documentation should help you construct what you need.
dear friend 1- thanks to your reply it works for part of my storedprocedure 2- i heard that CASE is not high performance statement 3- what should i do if i want to shorten this block of code?
if(@flag=1) then
select * from TBL1
ELSE
select * from TBL2i think this is not applicable to using CASE am i right?
-
dear friend 1- thanks to your reply it works for part of my storedprocedure 2- i heard that CASE is not high performance statement 3- what should i do if i want to shorten this block of code?
if(@flag=1) then
select * from TBL1
ELSE
select * from TBL2i think this is not applicable to using CASE am i right?
1. No problem 2. This does not make any more sense than "for loops are not high performance statements". 3. Assuming TBL1 and TBL2 have identical structure, you can do it like this:
select * from TBL1 where @flag=1
union all
select * from TBL2 where @flag<>1 -
1. No problem 2. This does not make any more sense than "for loops are not high performance statements". 3. Assuming TBL1 and TBL2 have identical structure, you can do it like this:
select * from TBL1 where @flag=1
union all
select * from TBL2 where @flag<>1very nice thanks