SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 DATEADD Problem
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

macca
Posting Yak Master

Ireland
146 Posts

Posted - 09/11/2013 :  10:06:19  Show Profile  Reply with Quote
I am doing a Select that contains a DATEADD and I want to get the records 330 days after the Date in the column DatTimeIssued in table Record. Here is the code I am using:

SELECT        No, CustomerID
FROM            LicenceRecord
WHERE        (LicenceStatus = 'Active') AND (RenewalStatus = 'Current') AND (LicenceDateTimeIssued = DATEADD(DAY, 330, LicenceDateTimeIssued))


I am not getting any records returned but I should be as the data fits the query criteria.
Anyone know what I am doing wrong ?

djj55
Constraint Violating Yak Guru

USA
337 Posts

Posted - 09/11/2013 :  10:09:56  Show Profile  Reply with Quote
(LicenceDateTimeIssued = DATEADD(DAY, 330, LicenceDateTimeIssued) will never be true. one or the other needs to be a different column.

djj
Go to Top of Page

macca
Posting Yak Master

Ireland
146 Posts

Posted - 09/11/2013 :  10:16:22  Show Profile  Reply with Quote
how would you write it then ?
Go to Top of Page

djj55
Constraint Violating Yak Guru

USA
337 Posts

Posted - 09/11/2013 :  10:52:02  Show Profile  Reply with Quote
Not knowing the columns available, I cannot help.


Maybe something like
RecordDate > DATEADD(DAY, 330, LicenceDateTimeIssued)


djj
Go to Top of Page

ScottPletcher
Constraint Violating Yak Guru

USA
411 Posts

Posted - 09/11/2013 :  15:20:31  Show Profile  Reply with Quote
AND (LicenceDateTimeIssued < DATEADD(DAY, -330, GETDATE()))
Go to Top of Page

macca
Posting Yak Master

Ireland
146 Posts

Posted - 09/12/2013 :  05:34:56  Show Profile  Reply with Quote
Thanks guys for all your help.
That worked for me.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000