i need implement 2 variables save data result in query.
i have following query:
select *  (select location location, count(*) trucks truck group location) loc outer apply (     select          count(*) totalofcampaings,          sum(case when cc.campaing_status = 'complete' 1 else 0 end) campaingswithcompletestatus,          sum(case when cc.campaing_status = 'inprocess' 1 else 0 end) campaingswithinprocessstatus     campaingcontrol cc inner join truck t on cc.vin = t.vin      t.location = loc.location ) stat this query shows next table:
|location|trucks|totalofcampaings|campaingswithcompletestatus|campaingswithinprocessstatus
i need add column @ end, in new column need percent of campaings complete status, tried this:
percent = (campaingswithcompletestatus / totalofcamapings) * 100
but dont know how save values of query that.
something this:
select     loc.location,     loc.trunks,     stat.totalofcampaings,     stat.campaingswithcompletestatus,     stat.campaingswithinprocessstatus,     (1.0 * stat.campaingswithcompletestatus /stat.totalofcampaings) * 100 [percent]  (select location location, count(*) trucks truck group location) loc outer apply (     select          count(*) totalofcampaings,          sum(case when cc.campaing_status = 'complete' 1 else 0 end) campaingswithcompletestatus,          sum(case when cc.campaing_status = 'inprocess' 1 else 0 end) campaingswithinprocessstatus     campaingcontrol cc inner join truck t on cc.vin = t.vin      t.location = loc.location ) stat 
Comments
Post a Comment