Showing posts with label searched. Show all posts
Showing posts with label searched. Show all posts

Friday, March 9, 2012

how to subtract days from date variable in sql query?

Hi,

I've searched quite a bit for help with this syntax but have given up.

I need help with the where clause of a query using SQL SERVER that selects records a certain number of days before the current date. I have tried this and it's incorrect syntax:

WHERE (fldDate < ({ fn NOW() - 500 })

Can someone please help me out with correct syntax for this? thanks much.

Check out the DATEADD and DATEDIFF T-SQL functions. You could write something like this:

WHERE DATEADD(day, -500, GETDATE())

This is untested, but is the basic idea.

Don

|||This will work in a sql server stored procedure right? (I never learned what exactly T-SQL is, i know it's transact sql, but does that mean it will work in sql server enterprise manager for example?)|||

Hi,

These are the functions provided by SQL Server. It will surely work on SQL Server stored procedure.