Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
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
Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Friday, April 11, 2014 12:13 PM
Points: 697, Visits: 1,721
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: Yesterday @ 7:27 PM
Points: 12,744, Visits: 31,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

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1454980
Posted Tuesday, May 21, 2013 7:08 AM
Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Friday, April 11, 2014 12:13 PM
Points: 697, Visits: 1,721
Perfect!

Thanks Lowell. You are the man.



Post #1454983
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse