Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IF statement error

Status
Not open for further replies.

dobrios

Programmer
Dec 27, 2000
54
US
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
 
I think the problem is a little higher up.

I think you should use

SELECT @intRecCount = (SELECT COUNT(*) FROM dbo.CRC WHERE DateTime >= @dtTodayAM and DateTime <= @dtTodayPM)

instead of

SELECT @intRecCount = COUNT(*) FROM dbo.CRC WHERE DateTime >= @dtTodayAM and DateTime <= @dtTodayPM

because you are assigning a result of a SELECT statement to a variable


GL


Rosko
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top