| Author |
Topic |
|
Sarakumar
Posting Yak Master
108 Posts |
Posted - 2006-04-24 : 00:01:14
|
| Hai i have the similar requirment which was discussed earlier in this forum..using the same sample to aske for the questiondeclare @table table(cust_id int,cust_name varchar(20),action varchar(20),date_time datetime)insert into @tableselect 1, 'john', 'CallOperator', '2006-04-10 10:00' union allselect 1, 'john', 'Attend', '2006-04-10 10:01' union allselect 1, 'john', 'Hold', '2006-04-10 10:05' union allselect 1, 'john', 'Hold', '2006-04-10 10:08' union allselect 1, 'john', 'Attend', '2006-04-10 10:15' union allselect 2, 'jothi', 'CallOperator', '2006-04-10 20:00' union allselect 2, 'jothi', 'Attend', '2006-04-10 20:10'select cust_id, cust_name, sum(datediff(minute, s_datetime, e_datetime))from(select s.cust_id, s.cust_name, s.action as s_action, s.date_time as s_datetime, e.action as e_action, e.date_time as e_datetimefrom @table s inner join @table eon s.cust_id = e.cust_idand e.date_time = (select min(date_time) from @table x where x.cust_id = s.cust_idand x.action = 'Attend'and x.date_time > s.date_time)where (s.action ='CallOperator' or s.action ='Hold')and e.action = 'Attend') agroup by cust_id, cust_namehai in this i have added one more row...now it is giving me the wrong output now i need to get the wait time as (first 'CallOperator' time('2006-04-10 10:00') - immediate next attend ('2006-04-10 10:01' ) )+ (second hold + the immediate attend)...can u pls help me in this |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-04-24 : 01:09:27
|
declare @table table( cust_id int, cust_name varchar(20), [action] varchar(20), date_time datetime)insert into @tableselect 1, 'john', 'CallOperator', '2006-04-10 10:00' union allselect 1, 'john', 'Attend', '2006-04-10 10:01' union allselect 1, 'john', 'Hold', '2006-04-10 10:05' union allselect 1, 'john', 'Hold', '2006-04-10 10:08' union allselect 1, 'john', 'Attend', '2006-04-10 10:15' union allselect 2, 'jothi', 'CallOperator', '2006-04-10 20:00' union allselect 2, 'jothi', 'Attend', '2006-04-10 20:10'declare @table2 table( cust_id int, cust_name varchar(20), s_action varchar(20), s_datetime datetime, e_action varchar(20), e_datetime datetime)insert into @table2 (cust_id, cust_name, s_action, s_datetime, e_action, e_datetime)select cust_id, cust_name, s_action, max(s_datetime) as s_datetime, e_action, max(e_datetime) as e_datetimefrom ( select s.cust_id, s.cust_name, s.action as s_action, s.date_time as s_datetime, e.action as e_action, e.date_time as e_datetime from @table s inner join @table e on s.cust_id = e.cust_id and e.date_time = (select min(date_time) from @table x where x.cust_id = s.cust_id and x.action = 'Attend' and x.date_time > s.date_time) where (s.action ='CallOperator' or s.action ='Hold') and e.action = 'Attend') agroup by cust_id, cust_name, s_action, e_actionselect cust_id, cust_name, sum(datediff(minute, s_datetime, e_datetime))from @table2group by cust_id, cust_name KH |
 |
|
|
Sarakumar
Posting Yak Master
108 Posts |
Posted - 2006-04-24 : 02:18:34
|
| Thanks a lot for ur effort. is it very expensive to use table variable |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-04-24 : 02:20:51
|
not really. Unless you have millions of records. Just try it out and see the result KH |
 |
|
|
|
|
|