日期:2014-05-16  浏览次数:20975 次

sql多表多层联结报错、一直不行
SELECT   *

FROM   (SELECT   a.intID,   a.vhrCode   AS   编码,   a.vhrName   AS   名称,   a.vhrShortCode   AS   简码,   a.intProItemType,   b.vhrName   AS   分类,   a.intUnit,   c.vhrName   AS   单位,   a.decCost   AS   成本价,   a.decOutPrice   AS   零售单价,   a.intGainType,   d.vhrName   AS   提成方式,   a.decGainValue   AS   提成参数,   a.bitIsStop,   (case   when   a.bitIsStop=1   then   启用   else   启用)   AS   使用状态,   a.vhrRemark   AS   说明,   a.intDataType   AS   数据类型   FROM   (((ProductItem   AS   a   LEFT   JOIN   BaseData   AS   b   ON   a.intProItemType   =   b.intID)   LEFT   JOIN   BaseData   AS   c   ON   a.intUnit   =   c.intID)   LEFT   JOIN   BaseData   AS   d   ON   a.intGainType   =   d.intID   WHERE   a.intDataType=0   ORDER   BY   a.vhrCode))   AS   serItem


[img=http://g.hiphotos.baidu.com/zhidao/wh%3D450%2C600/sign=dd16aa55fc039245a1e0e90bb2a488f4/9a504fc2d5628535fb058eb990ef76c6a6ef6344.jpg][/img]



------解决方案--------------------
select * from (

SELECT a.intID, a.vhrCode AS 编码, a.vhrName AS 名称, a.vhrShortCode AS 简码, a.intProItemType, b.vhrName AS 分类, a.intUnit, c.vhrName AS 单位, a.decCost AS 成本价, a.decOutPrice AS 零售单价, a.intGainType, d.vhrName AS 提成方式, a.decGainValue AS 提成参数, a.bitIsStop,
iif(a.bitIsStop=1,'启用','no启用') AS 使用状态, a.vhrRemark AS 说明, a.intDataType AS 数据类型 FROM ((ProductItem AS a LEFT JOIN BaseData AS b ON a.intProItemType = b.intID) LEFT JOIN BaseData AS c ON a.intUnit = c.intID) LEFT JOIN BaseData AS d ON a.intGainType = d.intID WHERE a.intDataType=0 ORDER BY a.vhrCode) AS serItem

or
select * from (
SELECT a.intID, a.vhrCode AS 编码, a.vhrName AS 名称, a.vhrShortCode AS 简码, a.intProItemType, b.vhrName AS 分类, a.intUnit, c.vhrName AS 单位, a.decCost AS 成本价, a.decOutPrice AS 零售单价, a.intGainType, d.vhrName AS 提成方式, a.decGainValue AS 提成参数, a.bitIsStop,
CASE WHEN a.bitIsStop=1 THEN '启用' ELSE 'no启用' END AS 使用状态, a.vhrRemark AS 说明, a.intDataType AS 数据类型 FROM ((ProductItem AS a LEFT JOIN BaseData AS b ON a.intProItemType = b.intID) LEFT JOIN BaseData AS c ON a.intUnit = c.intID) LEFT JOIN BaseData AS d ON a.intGainType = d.intID WHERE a.intDataType=0 ORDER BY a.vhrCode) AS serItem