Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
hdv212
Posting Yak Master
140 Posts |
Posted - 2008-05-01 : 07:20:29
|
hii have this script sample :declare @x nvarchar(30)declare @a nvarchar(30)set @x = 'Hi'set @a = (@x ='Hi' ? @x:'GoodBye') -- Error Messageselect @a in line 4, i want to check value of @x variable, if it has 'Hi' value, then pass @x value to @a, otherwise pass 'GoodBye'to @a. i want to do this checking by ? conditional operator, but sql server give me error :Incorrect syntax near '='. how to solve my problem ?thanks. |
|
|
RyanRandall
Master Smack Fu Yak Hacker
1074 Posts |
Posted - 2008-05-01 : 07:41:18
|
| set @a = case @x when 'Hi' then @x else 'GoodBye' endRyan Randall Solutions are easy. Understanding the problem, now, that's the hard part. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-05-01 : 07:42:03
|
| [code]declare @x nvarchar(30)declare @a nvarchar(30)set @x = 'Hi'set @a = case when @x ='Hi' then @x else 'GoodBye' end select @a[/code] |
 |
|
|
hdv212
Posting Yak Master
140 Posts |
Posted - 2008-05-01 : 12:34:22
|
| thanks allbut how to run this query :declare @a intdeclare @b intdeclare @c intset @a = 30set @b = 26set @c = case (@a - @b) when >= 0 then (@a - @b) else -1 end |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-05-01 : 12:43:29
|
quote: Originally posted by hdv212 thanks allbut how to run this query :declare @a intdeclare @b intdeclare @c intset @a = 30set @b = 26set @c = case when (@a - @b) >= 0 then (@a - @b) else -1 end
|
 |
|
|
|
|
|