虽然你有一万个理由,但是选择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, a.zy 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 [AC990财务软件]...[ID0000_PZGL_D] where kjn=2021 and kjy=10 and kmdm='100101' ) a left outer join [AC990财务软件]...[ID0000_YE] b on (a.kmdm=b.kmdm and b.kjn=2021 and b.kjy=10) left outer join [AC990财务软件]...[ID0000_PZGL_M] c on (a.pzh=c.pzh and c.kjn=2021 and 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, a.zy 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=2021 and kjy=10 and kmdm='100101' ) a left outer join ID0000_YE b on (a.kmdm=b.kmdm and b.kjn=2021 and b.kjy=10)
) left outer join ID0000_PZGL_M c on (a.pzh=c.pzh and c.kjn=2021 and c.kjy=10)
) order by a.pzh