我想要做的是将与 VhStock.No 关联的所有工作代码合并到一行中。任一列 WkRoDesc.Job_Code END AS WorkNeeded 具有所有工作代码,但下面列出的四个用“,”分隔,然后在另一列中以相同的方式组合这四个工作代码。
SELECT
--other things selected here
vhstock.No AS [Tag #],
WkInvReg.Ro_Number
CASE WHEN WkRoDesc.Job_Code = 'Outside AOR'
OR WkRoDesc.Job_Code = 'AOR Del'
OR WkRoDesc.Job_Code = 'AOR L & G'
OR WkRoDesc.Job_Code = '/Cust PU/D'
THEN NULL ELSE WkRoDesc.Job_Code END AS WorkNeeded,
CASE WHEN WkRoDesc.Job_Code = 'Outside AOR'
OR WkRoDesc.Job_Code = 'AOR Del'
OR WkRoDesc.Job_Code = 'AOR L & G'
OR WkRoDesc.Job_Code = '/Cust PU/D'
THEN WkRoDesc.Job_Code ELSE NULL END AS DPO
FROM vhstock, WkInvReg, WkRoDesc
WHERE vhstock.no = WkInvReg.Stock_No AND WkInvReg.Ro_Number = WkRoDesc.Ro_Number
我正在使用带有 ODBC 连接的 SQL Server 08 R2 从 SQL Anywhere v.11 数据库进行查询。我使用 Foresight Intelligence 作为界面来进行查询。我无法直接访问这两个数据库,因为它们是由软件供应商管理的。
我怎样才能做到这一点?已经尝试过了,但收到一个没有解释的错误
stuff((
select ',' + WkRoDesc.Job_Code + ', '
from WkRoDesc
where WkRoDesc.Ro_Number = WkInvReg.Ro_Number
and NOT (WkRoDesc.Job_Code = 'Outside AOR' OR WkRoDesc.Job_Code = 'AOR Del' OR WkRoDesc.Job_Code = 'AOR L & G' OR WkRoDesc.Job_Code = '/Cust PU/D')
FOR xml path('')
), 1, 1, '') AS WorkNeeded,
stuff((
select ',' + WkRoDesc.Job_Code + ', '
from WkRoDesc
where WkRoDesc.Ro_Number = WkInvReg.Ro_Number
and (WkRoDesc.Job_Code = 'Outside AOR' OR WkRoDesc.Job_Code = 'AOR Del' OR WkRoDesc.Job_Code = 'AOR L & G' OR WkRoDesc.Job_Code = '/Cust PU/D')
FOR xml path('')
), 1, 1, '') AS DPO