Input like 111111
and 101,102,103,104
I want to check whether user has access on this requests or not...
I tried a cursor as shown,
Depending on your SQL-Server Verion you can use a Table-Valued Function like in this short example
Select * from dbo.test1
Where ID in(
Select * from dbo.F_SplitAsIntTable('1,123,234,456'))
Function defined as
CREATE FUNCTION F_SplitAsIntTable
(
@txt varchar(max)
)
RETURNS
@tab TABLE
(
ID int
)
AS
BEGIN
declare @i int
declare @s varchar(20)
Set @i = CHARINDEX(',',@txt)
While @i>1
begin
set @s = LEFT(@txt,@i-1)
insert into @tab (id) values (@s)
Set @txt=RIGHT(@txt,Len(@txt)-@i)
Set @i = CHARINDEX(',',@txt)
end
insert into @tab (id) values (@txt)
RETURN
END
GO