Hi,
My sp code fails on IF statement and I don't see why.
I get an error:"Incorrect syntax near '1'", which is my IF statement below. If I print value of @intRecCount variable, it's not NULL. Appreciate any help. Steve
===========================================================
CREATE PROCEDURE dbo.sp_daily_report_post
AS
--declare some vars for later use
DECLARE @strMessage varchar (1000),
@strTitle varchar (50),
@strRecipients varchar(100),
@strToday varchar (50),
@dtTodayAM datetime,
@dtTodayPM datetime,
@intRecCount int
-- format today' date
SET @strToday = CONVERT(varchar(15), GETDATE(), 101)
SET @dtTodayAM = CAST(@strToday AS datetime)
SET @dtTodayPM = DATEADD(hh,23,@dtTodayAM)
SET @dtTodayPM = DATEADD(mi,55,@dtTodayPM)
-- get count from table and if there some records, create cursor, loop and get values for email
SELECT @intRecCount = COUNT(*) FROM dbo.CRC WHERE DateTime >= @dtTodayAM and DateTime <= @dtTodayPM
IF @intRecCount >= 1 'this is where it gives an error
My sp code fails on IF statement and I don't see why.
I get an error:"Incorrect syntax near '1'", which is my IF statement below. If I print value of @intRecCount variable, it's not NULL. Appreciate any help. Steve
===========================================================
CREATE PROCEDURE dbo.sp_daily_report_post
AS
--declare some vars for later use
DECLARE @strMessage varchar (1000),
@strTitle varchar (50),
@strRecipients varchar(100),
@strToday varchar (50),
@dtTodayAM datetime,
@dtTodayPM datetime,
@intRecCount int
-- format today' date
SET @strToday = CONVERT(varchar(15), GETDATE(), 101)
SET @dtTodayAM = CAST(@strToday AS datetime)
SET @dtTodayPM = DATEADD(hh,23,@dtTodayAM)
SET @dtTodayPM = DATEADD(mi,55,@dtTodayPM)
-- get count from table and if there some records, create cursor, loop and get values for email
SELECT @intRecCount = COUNT(*) FROM dbo.CRC WHERE DateTime >= @dtTodayAM and DateTime <= @dtTodayPM
IF @intRecCount >= 1 'this is where it gives an error