Author |
Topic |
nikoo56
Starting Member
26 Posts |
Posted - 2011-10-24 : 19:47:16
|
I have a report with this query:select source, created_by, first_name, last_name, type, dt_pro, dt_enrolled,counselor, email_1, wk_phone, address_1, city, state, zip, military_status, prospect_group, web_sourcefrom vwInternetProspects3 p with (nolock)where dt_pro between @start and @end and source in (@Source) and created_by in (@created_by) and prospect_group in (@prospect_group)order by p.counselorI have 3 queries to add 3 column to this report. I am not sure how merge these 3 queries with the query in the top to generate a report.select v.prospect_id, first_name, last_name, min(datediff(hour, v.dt_created, pc.dt_made)) as time_responsefrom vwInternetProspects3 vleft join tblC5ProspectCalls pc on pc.prospect_id = v.prospect_idleft join tblC5ProspectCallResultChoices cc on cc.call_result_id=pc.call_result_idwhere dt_pro > '10/1/11' and call_result = 'tt' group by v.prospect_id, first_name, last_nameselect v.prospect_id, first_name, last_name, count(*) as total_attemptfrom vwInternetProspects3 vleft join tblC5ProspectCalls pc on pc.prospect_id = v.prospect_idleft join tblC5ProspectCallResultChoices cc on cc.call_result_id=pc.call_result_idwhere dt_pro > '10/1/11' and call_type = 'OB'group by v.prospect_id, first_name, last_nameselect v.prospect_id, first_name, last_name, count(*) as total_talkfrom vwInternetProspects3 vleft join tblC5ProspectCalls pc on pc.prospect_id = v.prospect_idleft join tblC5ProspectCallResultChoices cc on cc.call_result_id=pc.call_result_idwhere dt_pro > '10/1/11' and call_result = 'tt' group by v.prospect_id, first_name, last_name |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-25 : 00:07:43
|
you mean you need to add time_response,total_attempt & total_talk to main query results? what are common columns the different queries have?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
nikoo56
Starting Member
26 Posts |
Posted - 2011-10-25 : 17:54:47
|
Ok I figure out the query in the report is like this but count(*) as total_attempt and count(*) as total_talk right now show same value. select source, created_by, first_name, last_name, type, dt_pro, dt_enrolled, counselor, email_1, wk_phone, address_1, city, state, zip, military_status, prospect_group, web_source,p.prospect_id,min(datediff(hour, p.dt_created, pc.dt_made)) as time_response,count(*) as total_attempt,count(*) as total_talkfrom vwInternetProspects3 p with (nolock)left join tblC5ProspectCalls pc on pc.prospect_id = p.prospect_idleft join tblC5ProspectCallResultChoices cc on cc.call_result_id=pc.call_result_idwhere dt_pro between @start and @endand source in (@Source)and created_by in (@created_by)and prospect_group in (@prospect_group)and (dt_pro > '10/1/11' and call_result = 'tt') or(dt_pro > '10/1/11' and call_type = 'OB')or(dt_pro > '10/1/11' and call_result = 'tt' )group by source, created_by, first_name, last_name, type, dt_pro, dt_enrolled, counselor, email_1, wk_phone, address_1, city, state, zip, military_status, prospect_group, web_source,p.prospect_idorder by p.counselor |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-26 : 01:08:03
|
[code]select *from(select source, created_by, first_name, last_name, type, dt_pro, dt_enrolled,counselor, email_1, wk_phone, address_1, city, state, zip, military_status, prospect_group, web_sourcefrom vwInternetProspects3 p with (nolock)where dt_pro between @start and @endand source in (@Source)and created_by in (@created_by)and prospect_group in (@prospect_group))tinner join(select v.prospect_id, first_name, last_name, min(case when call_result = 'tt' then datediff(hour, v.dt_created, pc.dt_made) else null end) as time_response,count(case when call_type = 'OB' then 1 else null end) as total_attempt,count(case when call_result = 'tt' then 1 else null end) as total_talkfrom vwInternetProspects3 vleft join tblC5ProspectCalls pc on pc.prospect_id = v.prospect_idleft join tblC5ProspectCallResultChoices cc on cc.call_result_id=pc.call_result_idwhere dt_pro > '10/1/11' group by v.prospect_id, first_name, last_name)uon u.prospect_id = t.prospect_idorder by t.counselor[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|