sql server - TSQL Updating Table with Counts from Other -
i have stored procedure creating , having little trouble coming logic.
i have table contains list of queue names such (bugs, support, etc).
i making page going show of queues along total number of tickets in each one.
i first created temp table , populated list of queue names. trying figure out how update temp table list of counts each of queue names.
in example below, there 4 queues , 1 ticket. saying each queue has 1 ticket incorrect.
any better approach this?
-- create temp table hold of queues , counts declare @table table ( reqqueue varchar (100), totalrecords int null); -- load our temp table data insert @table (reqqueue) select reqqueue apssupport_queues; -- update counts each of queues update @table set totalrecords = (select count(reqid) apssupport_tickets t t.reqqueue = reqqueue) reqqueue = reqqueue;
no need temp table:
select reqqueue, count(t.reqid) totalrecords apssupport_queues q left join apssupport_tickets t on q.reqqueue = t.reqqueue group q.reqqueue
Comments
Post a Comment