// Create function
create FUNCTION [dbo].[CommanTable_CommaSaparated_FromSaparated](@StrClm VARCHAR(MAX),@Flag int)
RETURNS VARCHAR(MAX)
BEGIN
DECLARE @ListStr VARCHAR(MAX),@Ids varchar(50) = ''
set @Ids=','+@StrClm+','
SELECT @ListStr = COALESCE(@ListStr+',' ,'') + Value FROM
tblMstCommon where Charindex(','+cast(ID as varchar(8000))+',', @Ids) > 0 and Flag=@Flag
RETURN @ListStr
END
// Call function
select dbo.CommanTable_CommaSaparated_FromSaparated('1,2,3,',525)as Result
// REsult
No comments:
Post a Comment