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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 MSSQL With RollUp Problem

Author  Topic 

Gerald30
Yak Posting Veteran

62 Posts

Posted - 2012-06-18 : 06:05:38
Hello All,

Can someone tell me what is wrong with my Query?


select
a.prid,
a.jo,
'SCL' as 'Process',
a.prdt,
isnull(a.model, 'Total'),
a.shift,
a.bbc,
a.sbc,
a.input,
a.tqty,
a.output,
a.outvar,
a.tyld,
a.actyield,
a.yvar,
a.wip
from
(
select
all_prs_id as 'PRID',
all_pdt as 'PRDT',
all_shf as 'Shift',
all_job as 'JO',
all_mdl as 'Model',
sum(all_bb) as 'Bbc',
sum(all_sb) as 'SBC',
sum(all_inp_qty) as 'Input',
sum(all_tgt_out) as 'TQty',
sum(all_out_qty) as 'Output',
sum(all_tgt_out) - sum(all_out_qty) as 'OutVar',
sum(all_tgt_yld) as 'tyld',
((sum(all_out_qty) / sum(all_inp_qty)) * 100) as 'ACTyield',
sum(all_tgt_yld) - ((sum(all_out_qty) / sum(all_inp_qty)) * 100) as 'YVar',
sum(all_wip) as 'WIP'
from con_all_001
where all_prs_id = 13 and all_pss = 1
group by all_shf, all_mdl, all_pdt, all_job, all_prs_id) a
where a.prdt between '2012-06-17' and '2012-06-17'
group by a.model with rollup




I was hoping that it should Group it by Shift since I have Group it on my inner query but it only returns 1 shift.

How can I group it by shift?

Please help me

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2012-06-18 : 06:17:51
Nope - the group by in the outer query is model so there will be one row per model returned.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -