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 |
|
avijit_mca
Posting Yak Master
109 Posts |
Posted - 2010-01-04 : 02:36:40
|
| I have table say tab1 with below data.Tab1 col1 col210 1520 2526 3035 40I want result like 16 1931 34using self join. please i need this code.Regards,avijit |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-01-04 : 02:53:40
|
| can you explain how you think you get displayed output? |
 |
|
|
avijit_mca
Posting Yak Master
109 Posts |
Posted - 2010-01-04 : 03:40:37
|
| i want sequence of no.see the table .seq 10 to 15seq gap 16-19again seq 20-25again seq 26-30gap seq 31 to 34again seq 35 to 40.Hope u understand. real life scenario like emp involve in project . i want to find emp idle time.Regards,avijit |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-01-04 : 03:56:37
|
for emp,just do likeSELECT t.empid,t1.col2+1,t.col1-1FROM Yourtable tCROSS APPLY (SELECT TOP 1 col2 FROM Yourtable WHERE empid=t.empid AND col2 < t.col1 ORDER BY col2 DESC)t1WHERE t1.col2 < t.col1-1 |
 |
|
|
|
|
|