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)
 exit stored procdure

Author  Topic 

carmitage
Starting Member

8 Posts

Posted - 2008-11-03 : 11:53:08
How can I exit a stored procedure within a case statement? This doesn't work, but for example within a stored procedure:

select
case when
count(*) > 1
then
begin
'Display a message'
RETURN
end
else
'Display a different message'
end
from alm.dbo.ANALYSIS_TEMP

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-11-03 : 11:55:15
you can't exit it in the case statement.

explain in more detail what your objective is and we can suggest other approaches.

_______________________________________________
Causing trouble since 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.1 out!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-03 : 11:56:19
the statement itself is wrong it should be this i guess

if (select count(*) from alm.dbo.ANALYSIS_TEMP) > 1
'Display a message'
else
'Display a different message'
Go to Top of Page

carmitage
Starting Member

8 Posts

Posted - 2008-11-03 : 11:58:29
If there is data in ANALYSIS_TEMP, I want to exit the stored procedure.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-03 : 12:00:29
quote:
Originally posted by carmitage

If there is data in ANALYSIS_TEMP, I want to exit the stored procedure.


i think what you need to do is to have a bit field on your procedure/function and based on whether it has data in table or not, just return value as 1 or 0
Go to Top of Page

bjoerns
Posting Yak Master

154 Posts

Posted - 2008-11-03 : 13:07:53
Mladen, caught you in the act! CASE is not a statement! :-)

http://weblogs.sqlteam.com/jeffs/archive/2007/05/03/60195.aspx
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-11-03 : 13:10:59
aww shucks! now i'm going to go dust myself with ash


_______________________________________________
Causing trouble since 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.1 out!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-11-04 : 01:38:37
quote:
Originally posted by visakh16

the statement itself is wrong it should be this i guess

if (select count(*) from alm.dbo.ANALYSIS_TEMP) > 1
'Display a message'
else
'Display a different message'



More effeciently
if exists(select * from alm.dbo.ANALYSIS_TEMP)
'Display a message'
else
'Display a different message'

Madhivanan

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

- Advertisement -