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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Nested IF statements?

Author  Topic 

tehprince
Starting Member

9 Posts

Posted - 2008-11-14 : 12:04:45
I'm looking to do the following in my SP:

IF @param1 = 1
select blah
from blah
where blah = blah

if @param2 = 2
group by different
else
do something else

ELSE
blah

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-14 : 12:09:45
you cant group conditionally like this. you need to use CASE..WHEN..ELSE in GROUP BY for this.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-11-15 : 01:48:57
or you can very well use IF THEN logic too

Madhivanan

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

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-15 : 04:46:49
quote:
Originally posted by madhivanan

or you can very well use IF THEN logic too

Madhivanan

Failing to plan is Planning to fail


But not like what OP posted anyways
Each branch should contain a whole SELECT query.
Go to Top of Page
   

- Advertisement -