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 |
|
Kalaiselvan
Posting Yak Master
112 Posts |
Posted - 2011-03-02 : 22:47:24
|
| TABLE1:ID UniqueId DATE TIME Q2 Q3 Info1 Info2 Info3 1 100 03/01/2011 17:40:37 1 11 NULL 9092892450 NULL2 100 03/01/2011 17:40:42 19 0 5000 NULL NULL3 100 03/01/2011 17:40:51 20 0 5000 NULL NULL4 100 03/01/2011 17:40:59 15 0 5000 NULL NULL5 100 03/01/2011 17:41:07 16 0 5000 NULL NULL6 100 03/01/2011 17:41:16 17 0 5000 NULL NULL7 100 03/01/2011 17:41:23 18 10 46 101 NULL8 100 03/01/2011 17:41:29 18 7 46 6 19 101 03/02/2011 17:42:28 1 11 NULL 9940640699 NULL10 101 03/02/2011 17:42:40 20 0 5000 NULL NULL11 101 03/02/2011 17:42:45 1 1 1 1 112 102 03/02/2011 17:42:58 1 11 NULL 9940540588 NULL13 102 03/02/2011 17:43:05 20 0 5000 NULL NULL14 102 03/02/2011 17:43:15 15 0 5000 NULL NULL15 102 03/02/2011 17:43:22 16 0 5000 NULL NULL 17 102 03/02/2011 17:43:23 18 10 46 101 NULL18 102 03/02/2011 17:43:39 18 8 46 16 1 Above is my sample table records. There you can find UniqueId column. It Reference each call transaction. For each Unique Id there may be Multiple columns. I need the output as single row for each Unique Id..Will explain how the Output should. I need 6 columns as my output.Column follows...UniqueID: Distinct Unique IdDate: Unique Date for each Unique IdTime: Time from Unique Id with Q3=11MDN: Info2 from UniqueId with Q3=11Status: Q3 from UniqueId (If Q3=1 Then 'NO ANSWER'. If Q3 IN (7,8) Then 'ANSWER'. Here Q3 IN (7,8) must be come from Q3=10)Duration: Info2 from uniqueId (If Q3=1 Info2 Value If Q3 IN (7,8) Info2 Value AND Q3 IN (7,8) must be come from Q3=10) Hence the Output Must be:UNIQUEID DATE TIME MDN STATUS DURATION 100 03/01/2011 17:40:37 9092892450 ANSWER 6 101 03/02/2011 17:42:28 9940640699 NO ANSWER 1 102 03/02/2011 17:42:58 9940540588 ANSWER 16Please help in this to built a Query ASAP. Its all comes from Sub Query within the table. It must be Distinct no repetition. Its sample records I will get 1000 of records per day. Regards,Kalaiselvan RLove Yourself First.... |
|
|
lappin
Posting Yak Master
182 Posts |
Posted - 2011-03-11 : 07:05:18
|
| Select distinct UNIQUEID, Date, Case when Q3=11 then TIME else null end as Time, Case when Q3=11 then Info2 else null end as MDN, Case when Q3=1 Then 'NO ANSWER' else Q3 end as STATUS, Case Q3when 1 then Info2when 7 then Info2 --I lost your logic hereelse '......' end as DURATION |
 |
|
|
|
|
|