sql 2005+ 行转列 outer apply 和 for xml
SELECT fitemid, supply
FROM(SELECT DISTINCT FItemID FROM t_supplyentry
where FDisableDate>=dateadd(dd,-day(getdate())+1,getdate()) --失效日期大于当月第一天
and FQuoteTime<=dateadd(ms,-3,DATEADD(mm, DATEDIFF(m,0,getdate())+1, 0))--有效日期小于当月最后一天
)A OUTER APPLY(
SELECT [supply]=stuff(
(
SELECT distinct ','+b.fname FROM t_supplyentry N left join t_Supplier b on N.fsupid=b.fitemid
WHERE N.FItemID = A.FItemID
FOR XML path('')
),1,1,'')
)N