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
 insert if..else

Author  Topic 

shemayb
Posting Yak Master

159 Posts

Posted - 2007-06-12 : 22:57:09
Can i insert an if...else statement in a select statement?

Funnyfrog

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-06-12 : 22:58:28
No. You have to use case when . .. statement


KH

Go to Top of Page

shemayb
Posting Yak Master

159 Posts

Posted - 2007-06-12 : 23:20:48
is case when statement the only option?

Funnyfrog
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-06-12 : 23:23:39
Depending on your situation. Basically you can't use if . . else statement within a select statement.


KH

Go to Top of Page

shemayb
Posting Yak Master

159 Posts

Posted - 2007-06-12 : 23:40:45
is it proper to put the case when statement in the where clause?

Funnyfrog
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-06-12 : 23:46:29
it is not wrong to use it in where clause or anywhere in the query as long as the syntax allows it.


KH

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-06-13 : 08:38:37
quote:
Originally posted by shemayb

is it proper to put the case when statement in the where clause?

Funnyfrog

Can you post some sample data and the result you want?

Madhivanan

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

- Advertisement -