April 16, 2009 at 1:07 pm
I wanted to run a stored proc based on a the following condition
If
Select Count(*) from Table>0
Then
Exec StoredProc
Else Don't Exec
How do I do this? Please help!
April 16, 2009 at 1:17 pm
IF EXISTS (SELECT * FROM table)
EXEC StoredProc
---------------------------------------------
[font="Verdana"]Nothing is impossible.
It is just a matter of time and money.[/font]
April 16, 2009 at 1:25 pm
Let me clarify
If the count returns 0 -- I don't run the SP
If count>0 I run the sp
Table will always be there. SP runs when table has data. Doesn't run when table has no data.
April 16, 2009 at 1:32 pm
Yes, that should work. I assume you call the SP from within another SP.
---------------------------------------------
[font="Verdana"]Nothing is impossible.
It is just a matter of time and money.[/font]
April 16, 2009 at 1:32 pm
I added
(Select Count(*) from Table)>0 in the where clause and it seemed to have worked
April 16, 2009 at 1:33 pm
Thanks JacekO
April 16, 2009 at 3:03 pm
david.chakraborty (4/16/2009)
I added(Select Count(*) from Table)>0 in the where clause and it seemed to have worked
The EXISTS function is faster.
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
April 16, 2009 at 3:20 pm
The EXISTS function returns true if there is at least one row returned from the query. Using EXISTS will be faster than a count.
Jeffrey Williams
“We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”
― Charles R. Swindoll
How to post questions to get better answers faster
Managing Transaction Logs
April 16, 2009 at 3:25 pm
Thanks Everyone! I have already made the change.
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply