April 27, 2010 at 8:27 am
T_SQL is wrong, some help is much appreciated.
IF EXISTS (SELECT DATEPART(hh, scheduledtime)
FROM intakesource_daily
WHERE DATEPART(hh, GETDATE()) > DATEPART(hh,scheduledtime))
BEGIN
IF EXISTS (SELECT DATEPART(mi, scheduledtime)
FROM intakesource_daily
WHERE DATEPART(mi, GETDATE()) > DATEPART(mi,scheduledtime))
THEN
PRINT 'File is late'
ELSE
END
April 27, 2010 at 9:11 am
just syntax...there is no IF<condition>THEN<statement>, only IF <condition><statement>
IF EXISTS (SELECT DATEPART(hh, scheduledtime)
FROM intakesource_daily
WHERE DATEPART(hh, GETDATE()) > DATEPART(hh,scheduledtime))
BEGIN
IF EXISTS (SELECT DATEPART(mi, scheduledtime)
FROM intakesource_daily
WHERE DATEPART(mi, GETDATE()) > DATEPART(mi,scheduledtime))
PRINT 'File is late'
ELSE
PRINT 'File is on time'
END
Lowell
April 27, 2010 at 12:29 pm
Also, you probably don't want those two nested if statements. (unless you do...)
The way you have it now, if there's a intake scheduled for 5:45, and another scheduled for 3:11 and the current time is 4:15, you're going to say the file is late.
What you probably want is to have both criteria true on a single record. unless you don't.
-a.
Dan Guzman - Not the MVP (7/22/2010)
All questions have to be prefaced by Server version and 'according to MS Docs' or 'my own personal opinion based on how much detail I felt like digging into at the time.'
April 27, 2010 at 12:58 pm
--declare a table variable
declare @intakesource_daily table
(scheduledTime datetime)
--insert a testing value
insert into @intakesource_daily(scheduledTime)
values ('2010-04-27 14:56:40.993')
--if the scheduledtime < getdate(),then print 'file is late'
IF EXISTS
(SELECT DATEPART(hh, scheduledtime) FROM @intakesource_daily WHERE DATEPART(hh, GETDATE()) > DATEPART(hh,scheduledTime)
or
(DATEPART(hh,GETDATE())=DATEPART(hh,scheduledTime) and DATEPART(mi, GETDATE()) > DATEPART(mi,scheduledTime)))
BEGIN
PRINT 'File is late'
END
April 27, 2010 at 7:38 pm
Thank you all for the replies! Great resources on this site!
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply