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 |
|
new_developer
Starting Member
18 Posts |
Posted - 2010-12-05 : 13:59:24
|
| hi for all i need sql statements to retrive the records which addbefore one week ,two week,one month and two month depend on the date column in databaase i want to retrive the records which add before week and so onany one can help me how i doing this thanks |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2010-12-05 : 14:07:11
|
| select *from tblwhere addeddate < datead(wk,-1,getdate())select *from tblwhere addeddate < datead(wk,-2,getdate())select *from tblwhere addeddate < datead(mm,-1,getdate())But I suspect that's not what you really want - you need to be a bit clearer.==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
new_developer
Starting Member
18 Posts |
Posted - 2010-12-09 : 16:15:42
|
| friend i try with your statmentbut it retrive all the records from databasei don't want don't thati want retrive the records added fromone week only no morecan you tell me how i do thisthanks |
 |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2010-12-09 : 16:48:59
|
| First you need a column that records the date that the record was added to the database. Do you have one?--Gail ShawSQL Server MVP |
 |
|
|
new_developer
Starting Member
18 Posts |
Posted - 2010-12-10 : 06:12:03
|
| i have column in database for datecall it date |
 |
|
|
pk_bohra
Master Smack Fu Yak Hacker
1182 Posts |
Posted - 2010-12-10 : 06:20:48
|
| How about changing the symbol used in nigel's solution :select *from tblwhere addeddate >= dateadd(wk,-1,getdate())select *from tblwhere addeddate >= dateadd(wk,-2,getdate())select *from tblwhere addeddate >= dateadd(mm,-1,getdate())If this is not your requirement then please pass on some sample data along with expected output. |
 |
|
|
|
|
|
|
|