Columns ->line,workorderno,bundleno,style,code,scandate,scantime
Actual sqlserver TBL like this
| Line | Workorderno | Bundleno | Style | code | scandate | ScanTime |
| l1 | 123 | 1210 | AC234 | 2 | 03-08-2013 | 10.11 |
| l1 | 123 | 1210 | AC234 | 1 | 03-08-2013 | 11.15 |
| l1 | 123 | 1210 | AC234 | 4 | 03-08-2013 | 13.17 |
| l1 | 123 | 1210 | AC234 | 3 | 03-08-2013 | 15.32 |
| l1 | 123 | 1210 | AC234 | 2 | 03-08-2013 | 10.14 |
| l1 | 123 | 1210 | AC234 | 1 | 05-08-2013 | 11.21 |
| l1 | 123 | 1211 | AS232 | 8 | 03-04-2013 | 14.52 |
| l1 | 123 | 1211 | AS232 | 7 | 04-04-2013 | 10.45 |
code -> odd Numbers are Send Scan code AND Even Numbers Are Recv Scan Code
EXPECTED RESULT
| Line | Workorderno | Bundleno | Style | code | senddate | SendTime | RecvDate | RecvTime |
| l1 | 123 | 1210 | AC234 | 03-08-2013 | 10.11 | 03-08-2013 | 11.15 | |
| l1 | 123 | 1210 | AC234 | 03-08-2013 | 13.17 | 03-08-2013 | 15.32 | |
| l1 | 123 | 1210 | AC234 | 03-08-2013 | 10.14 | 05-08-2013 | 11.21 | |
| l1 | 123 | 1211 | AS232 | 03-04-2013 | 14.52 | 04-04-2013 | 10.45 |
Please Help Me
Thanks in ADVS

Iftikar HussainRank #423 · 5.9K reputationPosted Aug 18, 2013, 8:38 PM EDT
Try like this
Regards,
Iftikar
Jignesh TrivediRank #16 · 50.3K reputationPosted Aug 18, 2013, 11:23 PM EDT
hi,
I think, It is very difficult to write query because there are so many duplicate value in your table.
in your datavalue there is no unique value on that we can partition.
can please provide more information?
Jignesh TrivediRank #16 · 50.3K reputationPosted Aug 19, 2013, 1:08 AM EDT
Try...
create table #Temp
(
line varchar(3),
workorderno int,
bundleno int,
style varchar(20),
code int,
scandate datetime,
scantime time
)
Insert into #Temp values
('l1',123, 1210, 'AC234', 2, '03-08-2013', '10:11'),
('l1',123, 1210 ,'AC234', 1, '03-08-2013', '11:15'),
('l1',123, 1210 ,'AC234', 4 , '03-08-2013', '13:17'),
('l1',123, 1210 ,'AC234', 3 , '03-08-2013', '15:32'),
('l1',123, 1210 ,'AC234', 2 , '03-08-2013', '10:14'),
('l1',123, 1210 ,'AC234', 1 , '05-08-2013', '11:21'),
('l1',123, 1211 ,'AS232', 8 , '03-04-2013', '14:52'),
('l1',123, 1211 ,'AS232', 7 , '04-04-2013', '10:45')
Select a.line,a.workorderno,a.bundleno,a.style, a.scandate as sendDate, a.scantime as sendTime,B.scandate recDate,B.scantime recTime from
(select *,ROW_NUMBER() OVER (ORDER BY code) as Rn from #Temp where code %2 =0) as A
join (select *,ROW_NUMBER() OVER (ORDER BY code) as Rn from #Temp where code %2 =1) B
on A.bundleno = b.bundleno and a.Rn = b.Rn and a.style = b.style
hope this will help you.
Parthiban B49 reputationPosted Aug 20, 2013, 3:39 AM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 20, 2013, 3:45 AM EDT
Parthiban B49 reputationPosted Aug 26, 2013, 3:02 AM EDT
(select *,ROW_NUMBER() OVER (ORDER BY code) as Rn from #Temp where code %2 =0) as A
join (select *,ROW_NUMBER() OVER (ORDER BY code) as Rn from #Temp where code %2 =1) B
on A.bundleno = b.bundleno and a.Rn = b.Rn and a.style = b.style
above query i didn't get full result
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 26, 2013, 3:05 AM EDT
Parthiban B49 reputationPosted Aug 27, 2013, 4:36 AM EDT
Please Find the Atachment