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 |
girisignin
Starting Member
11 Posts |
Posted - 2010-01-05 : 05:15:29
|
Hi i have some problem, here i posted the data11101 BLLI 0 12/10/09 5:3011101 25 0 12/10/09 6:5911101 PERN 1 12/11/09 23:3411101 32 1 12/12/09 1:1011101 BLLI 0 12/18/09 20:1211101 25 0 12/18/09 22:0711101 PERN 1 12/19/09 21:4011101 32 1 12/19/09 23:1611101 BLLI 0 12/26/09 5:4011101 25 0 12/26/09 7:3111101 PERN 1 12/27/09 14:0311101 25 0 12/27/09 16:2211101 PERN 1 12/28/09 13:4211101 25 0 12/28/09 16:04from the above data, i want to write a query to display data as below11101 BLLI 0 12/10/09 5:30 25 0 12/10/09 6:5911101 PERN 1 12/11/09 23:34 32 1 12/12/09 1:10etc..indly help me thank you |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-01-05 : 05:45:25
|
[code]SELECT t1.ID,t1.SecondField,t1.DateField,t2.ID,t2.SecondField,t2.DateField,FROM Table t1JOIN Table t2ON t2.ID=t1.IDAND t1.SecondField IN ('BLLI','PERN')AND t2.SecondField NOT IN ('BLLI','PERN')AND t2.DateField=(SELECT TOP 1 DateField FROM Table WHERE ID=t1.ID AND DateField < t1.DateField ORDER BY DateField DESC)[/code]replace fields with actual field names |
|
|
girisignin
Starting Member
11 Posts |
Posted - 2010-01-05 : 05:56:40
|
thank you in advancei will try this |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-01-05 : 06:06:34
|
good luck! |
|
|
|
|
|