February 13, 2003 at 10:26 am
Hello, I am new to SQl so sorry for the simple question. I have a stored procedure that is running every 5 minutes and throws out a XML file. It works fine except that it throws the file out even if the table is empty. How do I put an if statement into the SQL script to check to see if the table is empty before it proceeds? Thanks.
February 13, 2003 at 11:04 am
Do like so in your SP
if (select count(*) from tblname) != 0
begin
--do your xml stuff here
end
February 13, 2003 at 11:55 am
Worked Perfectly. Thanks alot for your help.
February 27, 2003 at 11:44 am
This is a small modification that is designed to boost performance:
if exists(select * from tblname)
begin
--do your xml stuff here
end
The EXISTS will terminate the select after the first record is found while the COUNT(*) will perform the entire select.
HTH
Steve Hendricks
MCSD, MCDBA
AFS Consulting Group
(949) 588-9800 x15
Steve Hendricks
MCSD, MCDBA
Data Matrix
shendricks@afsconsulting.com
(949) 588-9800 x15
February 27, 2003 at 12:39 pm
Oooooh, aaaaaw.
Cool, hadn't thought of that before.
February 27, 2003 at 12:42 pm
Thanks to both of you for helping me out.
February 28, 2003 at 11:06 am
That seems to be the case... but we have found that the internals seem to be more efficient with the COUNT than EXISTS (at least in tables with relatively small quantities of data...< 1000). You might want to run some tests is efficiency is an issue. Not a big deal, though. Even in our tests, the difference was only about 7%.
Guarddata-
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply