DECLARE @WithdrawnClasses VARCHAR(MAX) = ''
SELECT @WithdrawnClasses = COALESCE(@WithdrawnClasses + ', ', '') + fcd.ClassNbr
FROM XR.FrmCM9Details fcd
INNER JOIN XR.FrmCM9 fc ON fcd.FrmCM9FK = fc.Id
AND fc.FrmMstFK = '00775549-4EB9-478B-AFD5-5667BD9AA7EE'
SELECT @WithdrawnClasses
如果我运行此查询,我将返回输出为,01,03,05,29,35
那么有什么方法可以使用上面的查询修剪第一个逗号。所以结果应该是01,03,05,29,35
答案 0 :(得分:1)
请尝试:
select @WithdrawnClasses =STUFF(@WithdrawnClasses , 1, 1, '')
或删除变量@WithdrawnClasses
DECLARE @WithdrawnClasses VARCHAR(MAX)
SELECT
@WithdrawnClasses = COALESCE(@WithdrawnClasses + ', ', '') + fcd.ClassNbr
FROM XR.FrmCM9Details fcd
INNER JOIN XR.FrmCM9 fc ON fcd.FrmCM9FK = fc.Id
AND fc.FrmMstFK = '00775549-4EB9-478B-AFD5-5667BD9AA7EE'
答案 1 :(得分:0)
SELECT @WithdrawnClasses=SUBSTRING(@WithdrawnClasses,1,LEN(@WithdrawnClasses)-1)