Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Trying to fire this off, but only if there are results... Expand / Collapse
Author
Message
Posted Tuesday, May 21, 2013 6:54 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Today @ 1:53 PM
Points: 850, Visits: 2,358
Hi,

I'm using this bit of code to email results, but only if there are results/records:

IF select count(*) from (Select deddedcode as "DED CODE", dedlongDesc as DESCRIPTION, deddatetimecreated as DATE from dedcode where deddatetimecreated > DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), -55) > 0
begin

Get seem to figure out the syntax..



Post #1454974
Posted Tuesday, May 21, 2013 7:00 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 10:42 AM
Points: 14,469, Visits: 38,080
i think using EXISTS is a little better, and is what I would typically do:
--does ANY data match the criteria?
IF EXISTS (SELECT
1
FROM dedcode
WHERE deddatetimecreated > DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), -55)
)
BEGIN
--build a report with this data?
SELECT
deddedcode AS "DED CODE",
dedlongDesc AS DESCRIPTION,
deddatetimecreated AS DATE
FROM dedcode WHERE deddatetimecreated > DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), -55)
END




Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!
Post #1454980
Posted Tuesday, May 21, 2013 7:08 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Today @ 1:53 PM
Points: 850, Visits: 2,358
Perfect!

Thanks Lowell. You are the man.



Post #1454983
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse