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)
 get records previous 20 days from current date

Author  Topic 

gg0270
Starting Member

2 Posts

Posted - 2010-02-07 : 05:15:08
Hi,

I want to use the SELECT statement to get all my records from my table which is 20 days from the current date. I have been trying all ways but can't get it.. help will be appreciated!

SELECT WEIGHT, TIME, USER_ID
FROM dbo.WeightTable
WHERE (USR_ID = 'abc') AND 'LAST_UPDATED_TIME' >= DATE_SUB(CURDATE(), INTERVAL 15 DAY)

i am using ms sql server management studio express.. 2005 version. thanks!

gg0270
Starting Member

2 Posts

Posted - 2010-02-07 : 05:17:28
it says that the curdate function is not a built-in function name. can someone help me to correct statement?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-07 : 10:26:25
the function to get current date value in sql server is GETDATE(). Also there's no function like DATE_SUB in ms sql server. it should be


LAST_UPDATED_TIME >= DATEADD(day,-15,GETDATE())
Go to Top of Page
   

- Advertisement -