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.
Author |
Topic |
mkh
Starting Member
18 Posts |
Posted - 2004-08-22 : 03:43:53
|
I need to use Datediff function to find all entries from the last 30 days but my datatype is datetime.How can I do this using ONLY simgle select statement.Can anyone guide.regards,mkh. |
|
rockmoose
SQL Natt Alfen
3279 Posts |
Posted - 2004-08-22 : 04:36:17
|
select dateadd( day, -30, getdate() )/rockmoose |
|
|
mkh
Starting Member
18 Posts |
Posted - 2004-08-22 : 07:35:04
|
THIS DOES NOT WORKI want to select all records which are 30 days old from the table with column off type date time |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2004-08-22 : 07:41:01
|
select *from tblwhere dte >= dateadd(dd,-30,getdate())or if just the dayselect *from tblwhere dte >= dateadd(dd,-30,convert(varchar(8),getdate(),112))==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
|
|
mkh
Starting Member
18 Posts |
Posted - 2004-08-22 : 09:49:01
|
Hi ,Yes,the both queries seems ok for >= but for only oneday = does not work why??both give null results for = (1 one day)regardsMKh |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2004-08-22 : 14:19:20
|
>> find all entries from the last 30 daysDo you want that or just one days worthselect *from tblwhere convert(varchar(8),dte,112) = dateadd(dd,-30,convert(varchar(8),getdate(),112))select *from tblwhere dte >= dateadd(dd,-30,convert(varchar(8),getdate(),112))and dte < dateadd(dd,-29,convert(varchar(8),getdate(),112))==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
|
|
mkh
Starting Member
18 Posts |
Posted - 2004-08-23 : 04:49:03
|
Hi NKHi, Yes your first query works fine for user of 1 daythanks,mkh |
|
|
|
|
|
|
|