SET NOCOUNT ON
SELECT case when grouping (t1.F_name)=1 then 1 else 0 end as Fname_grouping,
t1.F_name as fname_nogrouping,
case when grouping(t1.F_name) = 1 then 101 else 0 end as fsumsort,
isnull(sum(T2.F_meter),0) as sum1,
isnull(sum(t3.F_weight),0) as sum2,
isnull(sum(t4.B_okmeter),0) as sum3,
isnull(sum(t5.F_meter),0) as sum4,
isnull(sum(t6.F_weight),0) as sum5,
isnull(sum(t7.B_okmeter),0) as sum6,
isnull(sum(t8.B_nometer),0) as sum7,
isnull(sum(t9.B_nometer),0) as sum8,
IDENTITY(int,1,1) AS column_name 
into #CrossTab1
from S_factory   T1   inner join S_jzout t2 on t1.F_name = t2.F_name
      inner join s_wsout t3 on t1.F_name = t3.F_name
      inner join S_OKclothback t4 on t1.F_name = t4.F_name
      inner join S_jzout t5 on t1.F_name = t5.F_name
      inner join S_wsout t6 on t1.F_name = t6.F_name
      inner join S_OKclothback t7 on t1.F_name = t7.F_name
      inner join S_noclothback t8 on t1.F_name = t8.F_name
                      inner join S_noclothback t9 on t1.F_name = t9.F_name
      where t2.F_jznorms = '75D' and  t2.F_date < '2009-10-01'
and t3.F_wsnorms =  '150D/144F' and t3.F_date < '2009-10-01'
and t4.B_Clothnorms =  '磨毛布75D150D/144F23梭225cm' and t4.B_date <'2009-10-01'
and t5.F_jznorms = '75D' and t5.F_date>= '2009-10-01' and t5.F_date <= '2009-10-30'
and t6.F_wsnorms = '150D/144F' and t6.F_date >='2009-10-01' and t6.F_date <= '2009-10-30'
and t7.B_Clothnorms = '磨毛布75D150D/144F23梭225cm' and t7.B_date>= '2009-10-01' and t7.B_date<='2009-10-30'
and t8.B_Clothnorms = '磨毛布75D150D/144F23梭225cm' and t8.B_date >= '2009-10-01' and t8.B_date <='2009-10-30' and t8.B_money>0
and t9.B_Clothnorms = '磨毛布75D150D/144F23梭225cm' and t9.B_date >= '2009-10-01' and t9.B_date <='2009-10-30' and t9.B_money=0
group by t1.F_name
with rollup
select case  Fname_grouping when 1 then ' ' when 2 then '' else Fname_Nogrouping end as Fname,
* into #crosstab2 from #CrossTab1  order by column_name 
drop table #CrossTab1
select Fname,sum1,sum2,sum3,sum4,sum5,sum6,sum7,sum8 from #crosstab2
drop table #crosstab2
我的写法有错误么?查询出来应该有数据,为何为空~~分不多了,帮帮忙吧