日期:2014-05-18  浏览次数:20466 次

一个奇怪的SQL语句
select * FROM JXCOUTSTORAGE A, JXCOUTSTORAGELIST B,JXCStorage C,CWOnlyCarCalculateFeeTbl D, WXOPERATEREPORTREPAIRTBL E
WHERE A.OUTSTORAGEID* = B.OUTSTORAGEID and B.STORAGEID*=C.STORAGEID and A.WorkNo*=D.WorkNo and a.workno* = e.workcodeing

------解决方案--------------------
这样试试
SQL code
select * 
FROM JXCOUTSTORAGE A
LEFT JOIN JXCOUTSTORAGELIST B ON A.OUTSTORAGEID = B.OUTSTORAGEID 
LEFT JOIN JXCStorage C ON B.STORAGEID=C.STORAGEI
LEFT JOIN CWOnlyCarCalculateFeeTbl D ON  A.WorkNo=D.WorkNo
LEFT JOIN WXOPERATEREPORTREPAIRTBL E ON a.workno= e.workcodeing

------解决方案--------------------
用* = 多条件时结果集是容易出错
楼主是SQL2000?这是SQL新版本废弃的功能
------解决方案--------------------
SQL code

MS SQL SERVER 支持两种形式表间连接
①从Sybase继承来的形式:
字段1 *= 字段2 (左连接)
字段1 =* 字段2 (右连接)
没有这种形式的全外连接语法
②标准的外连接语法
left [outer] join on 逻辑表达式
  right [outer] join on 逻辑表达式
full [outer] join (全外连接) on 逻辑表达式

------解决方案--------------------
2000版本以上的直接用连接或自然连接.就可以了
select * 
FROM JXCOUTSTORAGE A
LEFT JOIN JXCOUTSTORAGELIST B ON A.OUTSTORAGEID = B.OUTSTORAGEID 
LEFT JOIN JXCStorage C ON B.STORAGEID=C.STORAGEI
LEFT JOIN CWOnlyCarCalculateFeeTbl D ON A.WorkNo=D.WorkNo
LEFT JOIN WXOPERATEREPORTREPAIRTBL E ON a.workno= e.workcodeing

版主的