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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 case in sql server

Author  Topic 

pkuchaliya
Starting Member

49 Posts

Posted - 2008-09-04 : 09:02:50
hi frnd,

I want to perform the multiple checking with case . i want to check the different condition with case . is it possible to perform the given selection condition without if statement

if(@x)=1
begin
"sql statement"
end

if(@x)=2
begin
"sql statement"
end

if(@x)=3
begin
"sql statement"
end


pankaj

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-09-04 : 09:07:24
Are you changing the WHERE clause based on the condition?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2008-09-04 : 09:09:03
quote:
Originally posted by pkuchaliya

hi frnd,

I want to perform the multiple checking with case . i want to check the different condition with case . is it possible to perform the given selection condition without if statement

if(@x)=1
begin
"sql statement"
end

if(@x)=2
begin
"sql statement"
end

if(@x)=3
begin
"sql statement"
end


pankaj




declare @x int
select case when @x = 1 then 'Sql Stmt1'
when @x= 2 then 'Sql Stmt2'
when @x= 3 then 'Sql Stmt3'
end
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-09-04 : 09:11:14
quote:
Originally posted by raky

quote:
Originally posted by pkuchaliya

hi frnd,

I want to perform the multiple checking with case . i want to check the different condition with case . is it possible to perform the given selection condition without if statement

if(@x)=1
begin
"sql statement"
end

if(@x)=2
begin
"sql statement"
end

if(@x)=3
begin
"sql statement"
end


pankaj




declare @x int
select case when @x = 1 then 'Sql Stmt1'
when @x= 2 then 'Sql Stmt2'
when @x= 3 then 'Sql Stmt3'
end



That wont work if the SELECT returns more than a value

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -