我不是DBA,但我正在尽力收集大量数据并将其全部合并到一个单元格中。
obj.listaVehiculos.forEach(objVehiculoTemp => {
let objVehiculo = new Vehiculo(objVehiculoTemp.matricula,objVehiculoTemp.marca,objVehiculoTemp.modelo,objVehiculoTemp.anno,objVehiculoTemp.capacidad,objVehiculoTemp.kilometraje);
// process objVehiculoTemp.listaTrabajos
objVehiculo.listaTrabajos = objVehiculoTemp.listaTrabajos; // FOR EXAMPLE
objCliente.agregarVehiculo(objVehiculo);
});
我得到的输出是;
SELECT
ats.SupervisorSkillTargetID [AGENT],
STUFF ((SELECT '' + ats.AgentTeamID as [text()]
FROM Agent_Team_Supervisor ats
FOR XML PATH('') ), 1, 1, '' )[TEAM]
FROM
Agent_Team_Supervisor ats
WHERE
ats.SupervisorSkillTargetID = '1234'
ORDER BY
AgentTeamID
28次,这是表中提到的1234的次数,我试图输出1234,用户所属的所有TEAMS。
我意识到Team是INT而不是TEXT,但我似乎无法使用CAST或其他任何东西来合并它,
我希望看到的是;
AGENT | TEAM
-------------
1234 | 000500050015001500150015001500150015001500150015001500250025002500350035003500350035003500350035003500350035004500450045004500450065007500750075007500750085009500950095009500950095009500950095009500950095011501150115011501150115011501250125012501250125012501250135013501350135013501350135013501450145014501450145014501450145016501650165016501650165016501650165016501650165016501650165016501750175017501750175017501750175017501750185018501850185018501850185019501950195019501950195019501950195019501950205020502050205020502050205020502150215021502150215021502150215021502150215021502150215021502150215021502150215022502250225022502250225022502250245025502550255025502550255025502550255027502850285029503050305030503050305030503050305032503350345035503850385038503850385038503850385038503850385038503950395039503950395039503950395039503950395039504050405040504050405040504050405040504050405040504150415041504150415041504150415041504150415041504250425042504250425042504250425042504250425042504350435043504350435043
我不确定为什么首先插入'000',因为那不是,1234 Agent只能在一次中插入;
AGENT | TEAM
------+-------------------------
1234 | 5000, 5001, 5002, 5003
答案 0 :(得分:0)
declare @ats table (SupervisorSkillTargetID varchar(4)
default('1234'),AgentTeamID varchar(4))
insert into @ats (AgentTeamID)
select '5000' union select '5001' union select '5002' union select '5003'
union
select '5004' union select '5006' union select '5007' union select '5008'
union
select '5009' union select '5011' union select '5012' union select '5013'
union
select '5014' union select '5016' union select '5017' union select '5018'
union
select '5019' union select '5020' union select '5021' union select '5022'
union
select '5024' union select '5025' union select '5027' union select '5028'
union
select '5029' union select '5030' union select '5032' union select '5033'
union
select '5034' union select '5035' union select '5038' union select '5039'
union
select '5040' union select '5041' union select '5042' union select '5043'
SELECT distinct ats.SupervisorSkillTargetID [AGENT],
STUFF (( Select ',' + ats.AgentTeamID as [text()] FROM @ats ats where
SupervisorSkillTargetID='1234' FOR XML PATH('') ), 1, 1, '' )[TEAM]
FROM @ats ats
WHERE ats.SupervisorSkillTargetID = '1234'
ORDER BY [AGENT],team
结果是:
1234 5000,5001,5002,5003,5004,5006,5007,5008,5009,5011,5012,5013,5014,5016,5017,5018,5019,5020,5021,5022,5024,5025,5027,5028,5029,5030,5032,5033,5034,5035,5038,5039,5040,5041,5042,5043