求助:各位高人帮我看看这个SELECT语句怎么会这样!!!
Dim ConnectionString As String
Dim Rs1 As New ADODB.Recordset
Dim Conn1 As New ADODB.Connection
Dim SQL, SQL1 As String
ConnectionString = "Provider=sqloledb;Data Source=SERVER01;Initial Catalog=AIS20090326181431;User Id=SA;Password=;"
Conn1.Open ConnectionString
Rs1.CursorLocation = adUseClient
SQL1 = "SELECT AA1.仓库,AA1.日期,AA1.部门,AA1.单号,AA1.FITEMID AS 短码, " & _
"B.FName AS 名称,B.FModel AS 规格型号图号," & _
"AA1.入库数量,AA1.出库数量," & _
"AA1.单价,AA1.备注,G.FName AS 单位 " & _
"FROM (SELECT A1.*,A.FITEMID,CASE When A1.FTranType IN (1,2,10,40) Then A.FQty ELSE 0 END AS 入库数量," & _
"CASE When A1.FTranType IN (21,24,29,43) Then A.FQty ELSE 0 END AS 出库数量,A.FUnitID,A.FPrice AS 单价," & _
"A.FNote AS 备注" & _
"FROM (SELECT CASE WHEN E.FNAME IS NULL THEN E1.FNAME ELSE E.FNAME END AS 仓库," & _
"CONVERT(CHAR(10),C.FDATE,120) AS 日期," & _
"CASE WHEN D.FNAME IS NULL THEN (CASE WHEN D1.FNAME IS NULL THEN (CASE WHEN F.FNAME IS NULL " & _
"THEN '' ELSE F.FNAME END) ELSE D1.FNAME END) ELSE D.FNAME END AS 部门, " & _
"C.FBILLNO AS 单号, " & _
"C.FINTERID , C.FTranType " & _
"FROM ICSTOCKBILL C " & _
"LEFT JOIN T_SUPPLIER D ON C.FSupplyID=D.FItemID " & _
"LEFT JOIN t_Organization D1 ON C.FSupplyID=D1.FItemID " & _
"LEFT JOIN T_Stock E ON C.FDCSTOCKID=E.FITEMID " & _
"LEFT JOIN T_Stock E1 ON C.FSCSTOCKID=E1.FITEMID " & _
"LEFT JOIN t_Department F ON C.FDeptID=F.FITEMID " & _
"WHERE C.FDATE>='2009-08-01') A1 " & _
"LEFT JOIN ICSTOCKBILLENTRY A ON A1.FINTERID=A.FINTERID) AA1 " & _
"LEFT JOIN T_ICITEM B ON AA1.FITEMID=B.FITEMID " & _
"LEFT JOIN t_MeasureUnit G ON AA1.FUnitID=G.FItemID "
Rs1.Open SQL1, Conn1, adOpenDynamic, adLockOptimistic
上面的SQL1赋值SELECT语句,在SQL查询分析器中执行查询没问题,而怎么放在ACCESS中运行时提示错误:“运行时错误'-2147217900(80040e14),第1行:'('附近有语法错误。”
我先在此先谢谢各位了!!
------解决方案--------------------access没有case when啊
------解决方案-------------------- Rs1.Open SQL1, Conn1, adOpenDynamic, adLockOptimistic
在这个之前,看一下 SQL1中的内容是什么。
------解决方案--------------------JETSQL没有CASE WHEN,修改为IIF
------解决方案--------------------1. Case When 改成 IIF
2. join 多个JONT需要加上括号 ()
------解决方案--------------------你将SQL语句直接在ACCESS中测试一下
------解决方案--------------------建议楼上,仅贴出你的SQL语句而不是VB语句。
------解决方案--------------------