SQL DateDiff Query

Hi, My QL is rusty and I'd like some help to complete this. Should be easy for the experts!

What I'm trying to do below is this

If the dbo.NewCanvass.NextContactDate is greater than 30 days past the current date then display the text 'Red'

Once I get this working I can write the rest of the statement myself.  Thanks



SELECT     dbo.NewCanvass.id,

CASE WHEN (DATEADD(dd, DATEDIFF(dd, 0, dbo.NewCanvass.NextContactDate), 0) = DATEADD(dd, DATEDIFF(dd, 0, GETDATE()), 30)) THEN 'Red' as NextContactDate

END

Open in new window

EdAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

John EastonDirectorCommented:
I might be missing something, but I think all you need is:

SELECT     dbo.NewCanvass.id,

CASE WHEN dbo.NewCanvass.NextContactDate > DATEADD(dd, DATEDIFF(dd, 0, GETDATE()),30)) THEN 'Red' as NextContactDate

END 

Open in new window


It assumes NextContractDate is already a date time.
0
EdAuthor Commented:
Here is my complete statement

It keeps saying ' incorrect syntax near the keyword ' AS'


USE TestDb


SET QUOTED_IDENTIFIER ON
GO
Create Procedure [dbo].[TestProc]



AS
BEGIN

SELECT CASE WHEN dbo.NewCanvass.NextContactDate > DATEADD(dd, DATEDIFF(dd, 0, GETDATE()),30) THEN 'Red' AS NextContactDate

END  

Open in new window

0
John EastonDirectorCommented:
Try this:

SELECT CASE WHEN dbo.NewCanvass.NextContactDate > DATEADD(dd, DATEDIFF(dd, 0, GETDATE()),30) THEN 'Red' END AS NextContactDate

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
EdAuthor Commented:
Perfect, thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.