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 |
|
ianhollo
Starting Member
1 Post |
Posted - 2010-03-11 : 11:07:04
|
Is it possible if I have 4 different dates for the same piece of data, to retrieve the 3rd to last date i.e. something like this?Max([Date])-1I’ve tried the above but it does not work, and I thought maybe I could write some SQL to get the results I need?????Then next year when there are 5 dates for each set of data, I will need the 4th one; therefore l will always need the second to last date from the results.I'm working with Business Objects XI R2 "webi", but I cannot find the functionality in there.Thank you in advance everyone.ianhollo |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-03-11 : 11:09:36
|
Please provide table structure, sample data and wanted output in relation to the sample data.And the Version of SQL Server (2000 or 2005 or 2008). No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-03-11 : 11:12:47
|
possibleSELECT relevant columns...FROM(SELECT ROW_NUMBER() OVER (PARTITION BY <your core column group> ORDER BY Datefield DESC) AS Seq, other columns...FROM Table)tWHERE Seq < = 2 your core column group represents group of columns for whom you've four records with four different dates------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-03-11 : 11:23:11
|
Dear visakh,why it isn't possible to wait until OP gives proper information? I'm sure your approach (not wrong - sure) is the beginning of a ping pong...I thought about the same solution but I would like to have better information to give a reliable advice. No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-03-11 : 11:25:47
|
quote: Originally posted by webfred Dear visakh,why it isn't possible to wait until OP gives proper information? I'm sure your approach (not wrong - sure) is the beginning of a ping pong...I thought about the same solution but I would like to have better information to give a reliable advice. No, you're never too old to Yak'n'Roll if you're too young to die.
Actually I didnt see your reply. I was on a call after I typed solution and after posting realised that you had a post in betweenSorry------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-03-11 : 11:28:12
|
OK  No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|
|
|
|
|