Create a Funciton that convert comma seperated values to independent values.
Below is the function
CREATE Function [dbo].[FN_CsvToInt] ( @Array varchar(3000))
returns @IntTable table
(IntValue varchar(25))
AS
begin
declare @separator char(1)
set @separator = ','
declare @separator_position int
declare @array_value varchar(3000)
set @array = @array + ','
while patindex('%,%' , @array) <> 0
begin
select @separator_position = patindex('%,%' , @array)
select @array_value = left(@array, @separator_position - 1)
Insert @IntTable
Values (Cast(@array_value as varchar(25)))
select @array = stuff(@array, 1, @separator_position, '')
end
return
end
To select the values, write a query like this
select * from [FN_CsvToInt]('1,564,654,98,654,321,32,13,21,49')
Accept Solution if it helps you.