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 |
|
Rasta Pickles
Posting Yak Master
174 Posts |
Posted - 2012-10-25 : 08:03:40
|
| .....but keeping two?Is it possible?In English, my request would beSelect all records where created_date > 01/01/2012 but I also want to include ids 2440 and 2667 which were created in 2011.TIA. |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2012-10-25 : 08:09:39
|
| simplest would be to use a union - one query for current year and the other with a top 2 from previous data.==========================================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. |
 |
|
|
Mike Jackson
Starting Member
37 Posts |
Posted - 2012-10-25 : 08:15:43
|
| This should work.Select *from yourfile where created_date > 01/01/2012 or (id=2440 and year(created_date) = 2011)or (id=2667 and year(created_date) = 2011) |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2012-10-25 : 08:15:49
|
| Select all records where created_date > 01/01/2012 or ( id in (2440,2667) and created_date >= '20110101' and created_date < '20120101' )JimEveryday I learn something that somebody else already knew |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-10-25 : 10:13:09
|
quote: Originally posted by jimf Select all records where created_date > '20120101' or ( id in (2440,2667) and created_date >= '20110101' and created_date < '20120101' )JimEveryday I learn something that somebody else already knew
------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
Rasta Pickles
Posting Yak Master
174 Posts |
Posted - 2012-10-25 : 13:18:52
|
Thanks all |
 |
|
|
|
|
|