多行数据根据指定字符拼接,STUFF,XML

IF EXISTS(SELECT 1 FROM baseFinanceVoucherTempInfoDetail WHERE fitemID={fitemID})
BEGIN
	SELECT STUFF(( SELECT  ','+ voucherTempName FROM baseFinanceVoucherTempInfoDetail AS bd
	JOIN baseFinanceVoucherTempInfo AS bf ON bf.voucherTempID = bd.voucherTempID 
	WHERE fitemID={fitemID} FOR XML PATH('')), 1, 1, '') + ':以上凭证模板在用,不能删除此科目!'
	RETURN
END
IF EXISTS(SELECT 1 FROM produceMaterialOrder WHERE fitemID={fitemID})
BEGIN
	SELECT STUFF(( SELECT  ','+ orderCode FROM produceMaterialOrder WHERE fitemID={fitemID} FOR XML PATH('')), 1, 1, '') + ':以上领料单在用,不能删除此科目!'
	RETURN
END

你可能感兴趣的:(xml,sql,数据库)