当前位置: 代码迷 >> Sql Server >> 列前缀 'z' 与查询中所用的表名或别号不匹配
  详细解决方案

列前缀 'z' 与查询中所用的表名或别号不匹配

热度:140   发布时间:2016-04-27 11:47:06.0
列前缀 'z' 与查询中所用的表名或别名不匹配
如题:在数据库中查寻不出错,再eclipse里面就出现

上网差了半天也没解决 语句如下 

SELECT TOP 4 pi.companyName AS cname, z.ID AS zid, z.name AS zname, z.broough, 
  z.street, z.buildCount1, z.buildCount2, z.houseCount1, z.houseCount2, z.totalArea1, 
  z.totalArea2, z.occupyArea, z.businessArea, z.publicArea, z.rcommitteID, 
  z.developerID, dm.dept_name AS pname, z.completeTime, z.bankID, 
  di.name AS dname, z.address, z.publicAddress, z.businessAddress, z.Remark, 
  z.spare1, di2.name AS mname, z.spare2, z.spare3, z.spare4, z.spare5, z.bankName, 
  z.bankAccountNum
FROM [zone] z LEFT OUTER JOIN
  property_info pi ON z.spare2 = pi.ID LEFT OUTER JOIN
  disc_info di2 ON z.spare1 = di2.disc_id AND di2.type = 'B' LEFT OUTER JOIN
  disc_info di ON z.bankID = di.disc_id AND di.type = 'C' LEFT OUTER JOIN
  department dm ON CONVERT(int, REPLACE(dm.dept_id, 'k', '')) = z.developerID AND 
  dm.parentdept = 'KFS'
WHERE (z.spare2 = 191) AND (z.ID NOT IN
  (SELECT TOP 0 z.id
  FROM zone z LEFT JOIN
  property_info pi ON (z.spare2 = pi.ID) LEFT JOIN
  disc_info di2 ON (z.spare1 = di2.disc_id AND di2.type = 'B') LEFT JOIN
  disc_info di ON (z.bankID = di.disc_id AND di.type = 'C') LEFT JOIN
  department dm ON (CONVERT(int, replace(dm.dept_id, 'k', '')) 
  = z.developerID AND parentdept = 'KFS')
  WHERE z.spare2 = 191
  ORDER BY z.id))
ORDER BY z.ID

----------------


try {
String sqlstr_sub="pi.companyName as cname, z.ID as zid,z.name as zname,broough,street,buildCount1,buildCount2,houseCount1,houseCount2,totalArea1,";
sqlstr_sub+="totalArea2,occupyArea,businessArea,publicArea,rcommitteID,developerID,dm.dept_name as pname,completeTime,bankID,di.name as dname,address,";
sqlstr_sub+="publicAddress,businessAddress,Remark,z.spare1,di2.name as mname,z.spare2,z.spare3,z.spare4,z.spare5,bankName,bankAccountNum ";
sqlstr.append("select TOP " + pageSize + sqlstr_sub + " from zone z " )
.append(" left join property_info pi on (z.spare2 = pi.ID) ")
.append(" left join disc_info di2 on (z.spare1 = di2.disc_id and di2.type='B') ")
.append(" left join disc_info di on (z.bankID = di.disc_id and di.type='C') ")
.append(" left join department dm on (convert(int,replace(dm.dept_id,'k','')) = z.developerID and parentdept='KFS') ")
.append(" where " + sql + " and z.id not in ")
.append(" ( select TOP " + (pageNo-1)*pageSize + " z.id from zone z" )
.append(" left join property_info pi on (z.spare2 = pi.ID) " )
.append(" left join disc_info di2 on (z.spare1 = di2.disc_id and di2.type='B') ")
.append(" left join disc_info di on (z.bankID = di.disc_id and di.type='C') ")
.append(" left join department dm on (convert(int,replace(dm.dept_id,'k','')) = z.developerID and parentdept='KFS') ")
.append("where " + sql + " order by z.id ) order by z.id");
pstmt = con.prepareStatement(sqlstr.toString());
rs = pstmt.executeQuery();




-------

try {
connManager = DBConnectionManager.getInstance();
con = connManager.getConnection(sqlName);
sql = " z.spare2=" + sql + " ";
return this.getZoneInfoModelBySql(con, sql, pageNo, pageSize);




-------------------------------
sql = " z.spare2=" + sql + " ";

就是这句话出问题,我把代码都贴出来了,王高手看看。
  相关解决方案