Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Anyone see the syntax error with the following?

Author  Topic 

qman
Constraint Violating Yak Guru

442 Posts

Posted - 2010-03-29 : 11:44:09
When running the following query as an SP, I get the following error: "Incorrect syntax near '@YESTERCOUNT'.

Does anyone see what I am missing?

SELECT * INTO #YESTERDAY FROM PFradet.PAUL_TEST_DB2_TABLE
WHERE transaction_create_ts = CONVERT(VARCHAR(10), GETDATE() - 1, 120)

DECLARE @YESTERCOUNT int;
SELECT @YESTERCOUNT = (select count(*) from #YESTERDAY)
SELECT @YESTERCOUNT

IF @YESTERCOUNT < 0
BEGIN
PRINT 'DELETE YESTERDAYS RECORDS HERE'
END
ELSE
PRINT 'NOTHING TO DELETE0'

DROP TABLE @YESTERCOUNT
GO

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-03-29 : 11:47:35
The table name isn't @YESTERCOUNT that you want to drop.
It is #YESTERDAY.

By the way: how should the counter be less than zero?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-29 : 11:49:12
it should be @YESTERCOUNT > 0 as per logic I guess

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

qman
Constraint Violating Yak Guru

442 Posts

Posted - 2010-03-29 : 11:51:24
Duh, clear as day.....
The counter should be > 0 not less than.

I just want to print a message when the number of records in the temp table are > 0. Else, do something else.....
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-29 : 11:55:27
I think you need only this

IF EXISTS (SELECT 1 FROM PFradet.PAUL_TEST_DB2_TABLE
WHERE transaction_create_ts >= DATEADD(dd,DATEDIFF(dd,0,GETDATE()) - 1,0)
AND transaction_create_ts < DATEADD(dd,DATEDIFF(dd,0,GETDATE()),0))
PRINT 'DELETE YESTERDAYS RECORDS HERE'
ELSE
PRINT 'NOTHING TO DELETE0'

GO


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

qman
Constraint Violating Yak Guru

442 Posts

Posted - 2010-03-29 : 11:58:58
Visakh16, exactly... Why could'nt I have figured that out? Ahhh.

Thanks

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-29 : 12:02:18
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -