access的多个leftouterjoin连接
虽然你有⼀万个理由,但是选择ACCESS数据库就是⼀个不能再蠢的决定。
从AC990账务系统中采集凭证记录,需要做多个左连接。在sql server管理器中执⾏蛮好,没有问题。可是在程序中就⼀堆Error。说左连接。下⾯代码在管理器查询中执⾏是ok的。
select (replace(c.pzrq,'.','')+ a.pzlx +right('00000'+cast(a.pzh as varchar(5)),5)) as HDCD_ID,
'101'as HDCD_TypeCode,
'⼈员经费'as HDCD_TypeName,
c.pzrq as HDCD_Date,
< as HDCD_Summary,
a.kmdm as HDCD_DetailCode,
b.kmmc as HDCD_DetailName,
a.je as HDCD_DetailSum,
'ac990财务软件'as HDCD_Source,
a.pzh as HDCD_SourceNo,
'科室代码'as HD_No,
'科室名称'as HDCD_DeptName,
'科室⼤类'as HDCD_DeptType
sql left join 多表连接
from
(select*FROM[AC990财务软件]...[ID0000_PZGL_D]where  kjn=2021and kjy=10and kmdm='100101'
) a
left outer join[AC990财务软件]...[ID0000_YE] b on (a.kmdm=b.kmdm and b.kjn=2021and b.kjy=10)
left outer join[AC990财务软件]...[ID0000_PZGL_M] c on (a.pzh=c.pzh and c.kjn=2021and c.kjy=10)
order by a.pzh
在程序中就出错。错误有⼆个:
1、函数不识别。access有⾃⼰简单的函数。需要按照access⾃⼰的函数进⾏修改
2、数据表的表达,不识别。改成标标准格式
3、左连接表达式错误。每个left join需要括号()成对括起来:from ((  T1 left join T2  on ...)left join T3  on...)
我们改⼀下:
select'101'as HDCD_TypeCode,
'⼈员经费'as HDCD_TypeName,
c.pzrq as HDCD_Date,
< as HDCD_Summary,
a.kmdm as HDCD_DetailCode,
b.kmmc as HDCD_DetailName,
a.je as HDCD_DetailSum,
'ac990财务软件'as HDCD_Source,
a.pzh as HDCD_SourceNo,
'科室代码'as HD_No,
'科室名称'as HDCD_DeptName,
'科室⼤类'as HDCD_DeptType
from
(
(
(select*FROM ID0000_PZGL_D where  kjn=2021and kjy=10and kmdm='100101'
) a
left outer join ID0000_YE b on (a.kmdm=b.kmdm and b.kjn=2021and b.kjy=10)
)
left outer join ID0000_PZGL_M c on (a.pzh=c.pzh and c.kjn=2021and c.kjy=10)
)
order by a.pzh

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。