select count(sj_ycfjbzl.jbzlid) as ycf from  xt_dw,sj_ycfjbzl  where xt_dw.dwid = sj_ycfjbzl.localid and sj_ycfjbzl.scbz=0 and xt_dw.dwid like'530%' and year(jbzlrq)+month(jbzlrq)>='20091'
and year(jbzlrq)+month(jbzlrq)<='200912'
select * from sj_gwglxx
select  count(sj_cz.mumid) as cqjc from sj_cz,sj_cqjc where sj_cqjc.scbz=0select count(sj_gwglxx.gwid) as gwycf from  xt_dw,sj_gwglxx where xt_dw.dwid = sj_gwglxx.localid and sj_gwglxx.Scbz=0select count(sj_gwfz.gwfzid) as gwfz from  xt_dw,sj_gwfz where xt_dw.dwid = sj_gwfz.localid and sj_gwfz.scbz=0
select sum(case sj_fmjl.Ways_delivery when '自然分娩' then 1 else 0 end) as zrfm,
sum(case sj_fmjl.Ways_delivery when '阴道手术助产' then 1 else 0 end)as ydsszc,sum(case sj_fmjl.Ways_delivery when '剖宫产' then 1 else 0 end) as pgc   
from  xt_dw,sj_fmjl where xt_dw.dwid = sj_fmjl.localid and sj_fmjl.scbz=0
select sum(case when sj_etjbzl.fmjlid  is not null then 1 else 0 end) as xses from  xt_dw,sj_etjbzl  where xt_dw.dwid = sj_etjbzl.localid and sj_etjbzl.del=0select count(sj_sw_csqx_qxedjk.sjid) as csqxes from  xt_dw, sj_sw_csqx_qxedjk  where xt_dw.dwid = sj_sw_csqx_qxedjk.localid and sj_sw_csqx_qxedjk.del=0select  count(sj_tre.treid) as tres from  xt_dw ,sj_tre  where xt_dw.dwid = sj_tre.localid and sj_tre.del=0当然语句还有,只是列举了些,想这些查出来的数据要放到一张报表上显示,在代码或sql中有更好的办法没?

解决方案 »

  1.   

    建一个DataTable,将上列的sql所得数据依次放入DataTable中,
    然后将这个DataTable绑定到GridView即可!!
      

  2.   

    如果以上sql的列数类型相同,也可以将这些sql用union拼接,
    如:
    select  count(sj_cz.mumid) as a1 from sj_cz,sj_cqjc where sj_cqjc.scbz=0 
    union
    select count(sj_gwglxx.gwid) as a1 from  xt_dw,sj_gwglxx where xt_dw.dwid = sj_gwglxx.localid and sj_gwglxx.Scbz=0 
    union
    ...........
    这样和常规的一样绑定!!
    所要注意的是 as 后跟相同的名
      

  3.   

    select count(sj_ycfjbzl.jbzlid) as ycf from  xt_dw,sj_ycfjbzl  where xt_dw.dwid = sj_ycfjbzl.localid and sj_ycfjbzl.scbz=0 and xt_dw.dwid like'530%' and year(jbzlrq)+month(jbzlrq)>='20091' 
    and year(jbzlrq)+month(jbzlrq) <='200912' 这句能查出结果吗? 
    类似 
    year(jbzlrq)+month(jbzlrq) <='200912'  感觉不对吧。
    俩个整形加到一起跟一个char类型比较?
    select  count(sj_cz.mumid) as cqjc from sj_cz,sj_cqjc where sj_cqjc.scbz=0 :
    应该加上sj_cz,sj_cqjc 之间的关系把?不然这样的写法没有意义。
      

  4.   

    和普通建表脚本一样啊create table #temp_tb 
    ......