SQL Server 自定义函数(1)把某一列多行的值拼接成一个字符串

时间:2022-05-06 10:27:25
DECLARE @resultstr VARCHAR(8000)
SET @resultstr=''
SELECT @resultstr=@resultstr+'|'+[BaseImage] FROM  dbo.life_fc 
PRINT @resultstr

 示例2

DECLARE @imgColleciton VARCHAR(8000),@BaseID INT,@value VARCHAR(5000),@citcode VARCHAR(100),@type VARCHAR(100)
SET @imgColleciton=''
SELECT @citcode=BaseCityCode FROM dbo.life_fc
SELECT @type= BaseTypeID FROM dbo.life_fc
SELECT @imgColleciton=@imgColleciton+'|'+[BaseImage] FROM dbo.life_fc 
SELECT 'E:\cityresource7\cn\'+@citcode+'\zh-chs\etongcheng\'+cast(@type as varchar(8))+'\img'+value FROM [dbo].[SplitString](@imgColleciton,'|',0)