SQL How to correctly set a date variable value and use it?
Posted
by flavour404
on Stack Overflow
See other posts from Stack Overflow
or by flavour404
Published on 2010-04-29T20:04:45Z
Indexed on
2010/04/29
20:07 UTC
Read the original article
Hit count: 488
sql-server-2008
Hi,
I have the following query which uses a date variable, which is generated inside the stored procedure:
DECLARE @sp_Date DATETIME
SET @sp_Date = DateAdd(m, -6, GETDATE())
SELECT DISTINCT pat.PublicationID
FROM PubAdvTransData AS pat
INNER JOIN PubAdvertiser AS pa ON pat.AdvTransID = pa.AdvTransID
WHERE (pat.LastAdDate > @sp_Date) AND (pa.AdvertiserID = 12345))
The problem is that the @sp_Date value appears to be being ignored and I am wondering why? Have I defined or used it incorrectly?
sql microsoft sql-server-2008
User error...
Thanks, R.
© Stack Overflow or respective owner