gcbh 工厂编号,clbh 材料编号,kcsl 库存数量等等·select gcbh,clbh,
sum(kcsl) as kcsl,sum(lskcsl) as lskcsl,sum(rksl) as rksl,sum(tlsl) as tlsl,
sum(cksl) as cksl,sum(cklssl) as cklssl,sum(kctzsl) as kctzsl,sum(lskctzsl) as lskctzsl
from(
select gcbh,clbh,
sum(isnull(kcsl,0))as kcsl,sum(isnull(lskcsl,0)) as lskcsl,
0 as rksl,0 as tlsl,0 as cksl,0 as cklssl,0 as kctzsl,0 as lskctzsl
from
erp_kc_clkc
where
gcbh like :gcbh and clbh like :clbh
group by gcbh,clbh
union all
select gcbh,clbh,
0 as kcsl,0 as lskcsl,sum(isnull(rksl,0))as rksl,0 as tlsl,
0 as cksl,0 as cklssl,0 as kctzsl,0 as lskctzsl
from
erp_sc_clrkd a,erp_sc_clrk_detail b
where
a.rkdh=b.rkdh and a.shzt='1' and gcbh like :gcbh and clbh like :clbh and rkrq>= :rq1 and rkrq<= :rq2
group by gcbh,clbh
union all
select gcbh,clbh,
0 as kcsl,0 as lskcsl,0 as rksl,sum(isnull(tlsl,0))as tlsl,
0 as cksl,0 as cklssl,0 as kctzsl,0 as lskctzsl
from
erp_sc_cltld a,erp_sc_cltld_detail b
where
a.tldh=b.tldh and a.shzt='1' and gcbh like :gcbh and clbh like :clbh and tlrq>= :rq1 and tlrq<= :rq2
group by gcbh,clbh
union all
select gcbh,clbh,
0 as kcsl,0 as lskcsl,0 as rksl,0 as tlsl,
sum(isnull(cksl,0))as cksl,sum(isnull(cklssl,0))as cklssl,0 as kctzsl,0 as lskctzsl
from
erp_sc_clckd a,erp_sc_clck_detail b
where
a.ckdh=b.ckdh and a.shzt='1' and gcbh like :gcbh and clbh like :clbh and ckrq>= :rq1 and ckrq<= :rq2
group by gcbh,clbh
union all
select gcbh,clbh,
0 as kcsl,0 as lskcsl,0 as rksl,0 as tlsl,
sum(isnull(kcsl,0)-isnull(kcsl1,0)) as kctzsl,0 as cksl,0 as cklssl,
sum(isnull(lskcsl1,0)-isnull(lskcsl,0)) as lskctzsl
from
erp_sc_cltzd a,erp_sc_cltzd_detail b
where
a.tzdh=b.tzdh and a.shzt='1' and gcbh like :gcbh and clbh like :clbh and tzrq>= :rq1 and tzrq<= :rq2
group by gcbh,clbh
)a
group by gcbh,clbh 消息 170,级别 15,状态 1,第 11 行
第 11 行: ':' 附近有语法错误。
消息 170,级别 15,状态 1,第 20 行
第 20 行: ':' 附近有语法错误。
消息 170,级别 15,状态 1,第 29 行
第 29 行: ':' 附近有语法错误。
消息 170,级别 15,状态 1,第 38 行
第 38 行: ':' 附近有语法错误。
消息 170,级别 15,状态 1,第 48 行
第 48 行: ':' 附近有语法错误。
sum(kcsl) as kcsl,sum(lskcsl) as lskcsl,sum(rksl) as rksl,sum(tlsl) as tlsl,
sum(cksl) as cksl,sum(cklssl) as cklssl,sum(kctzsl) as kctzsl,sum(lskctzsl) as lskctzsl
from(
select gcbh,clbh,
sum(isnull(kcsl,0))as kcsl,sum(isnull(lskcsl,0)) as lskcsl,
0 as rksl,0 as tlsl,0 as cksl,0 as cklssl,0 as kctzsl,0 as lskctzsl
from
erp_kc_clkc
where
gcbh like :gcbh and clbh like :clbh
group by gcbh,clbh
union all
select gcbh,clbh,
0 as kcsl,0 as lskcsl,sum(isnull(rksl,0))as rksl,0 as tlsl,
0 as cksl,0 as cklssl,0 as kctzsl,0 as lskctzsl
from
erp_sc_clrkd a,erp_sc_clrk_detail b
where
a.rkdh=b.rkdh and a.shzt='1' and gcbh like :gcbh and clbh like :clbh and rkrq>= :rq1 and rkrq<= :rq2
group by gcbh,clbh
union all
select gcbh,clbh,
0 as kcsl,0 as lskcsl,0 as rksl,sum(isnull(tlsl,0))as tlsl,
0 as cksl,0 as cklssl,0 as kctzsl,0 as lskctzsl
from
erp_sc_cltld a,erp_sc_cltld_detail b
where
a.tldh=b.tldh and a.shzt='1' and gcbh like :gcbh and clbh like :clbh and tlrq>= :rq1 and tlrq<= :rq2
group by gcbh,clbh
union all
select gcbh,clbh,
0 as kcsl,0 as lskcsl,0 as rksl,0 as tlsl,
sum(isnull(cksl,0))as cksl,sum(isnull(cklssl,0))as cklssl,0 as kctzsl,0 as lskctzsl
from
erp_sc_clckd a,erp_sc_clck_detail b
where
a.ckdh=b.ckdh and a.shzt='1' and gcbh like :gcbh and clbh like :clbh and ckrq>= :rq1 and ckrq<= :rq2
group by gcbh,clbh
union all
select gcbh,clbh,
0 as kcsl,0 as lskcsl,0 as rksl,0 as tlsl,
sum(isnull(kcsl,0)-isnull(kcsl1,0)) as kctzsl,0 as cksl,0 as cklssl,
sum(isnull(lskcsl1,0)-isnull(lskcsl,0)) as lskctzsl
from
erp_sc_cltzd a,erp_sc_cltzd_detail b
where
a.tzdh=b.tzdh and a.shzt='1' and gcbh like :gcbh and clbh like :clbh and tzrq>= :rq1 and tzrq<= :rq2
group by gcbh,clbh
)a
group by gcbh,clbh 消息 170,级别 15,状态 1,第 11 行
第 11 行: ':' 附近有语法错误。
消息 170,级别 15,状态 1,第 20 行
第 20 行: ':' 附近有语法错误。
消息 170,级别 15,状态 1,第 29 行
第 29 行: ':' 附近有语法错误。
消息 170,级别 15,状态 1,第 38 行
第 38 行: ':' 附近有语法错误。
消息 170,级别 15,状态 1,第 48 行
第 48 行: ':' 附近有语法错误。
想表达什么意思
SQL的话,你直接把你的:gcbh换成对应的实际数据就可以了。
如like :gcbh -> like '%' + ':gcbh的值' + '%'
tzrq>= :rq1 -> tzrq >= ':rq1的值' 注意下类型就可以了
like 语法 like'%值%' 或 like'值%'或 like'%值' ‘值’的前后可以带 下划线 之类的格式
要么上面改成存储过程,接受参数,然后把上面的语句封装到存储过程里面去,然后把:gcbh 改成@gcbh的参数形式!!!!!!
要么上面改成存储过程,接受参数,然后把上面的语句封装到存储过程里面去,然后把:gcbh 改成@gcbh的参数形式!!!!!!