All I am having a little problem here is the sample code
create table Sections (ID int, name char(1), Description nvarchar(50))
insert into Sections values (1,'A','A Section')
insert into Sections values (2,'B','B Section')
insert into Sections values (3,'C','C Section')
insert into Sections values (4,'D','D Section')
insert into Sections values (5,'E','E Section')
insert into Sections values (6,'F','F Section')
select * from Sections
declare @Names nvarchar(10) ='A,B,C';
select *from Sections where name in (@Names)
What i want is that i will pass an string that string will be splited into each char and that char array will be passed in the where clause. I have tried it with numeric that works fine but in the char it not working properly. what i have done is like this
declare @Categories nvarchar(50)='ABC';
declare @array nvarchar(50);
declare @lenth int =len(@Categories);
Declare @c int =1;
declare @param nvarchar(50)='' ;
while @c <=@lenth
begin
set @param = @param + ''''+ SUBSTRING(@Categories ,@c,1) +''''+','
set @c =@c+1
end
print @param
declare @Cats nvarchar(50);
set @Cats= substring(@param, 0,len(@param)-0)
Its output like 'A','B','C'. but when i am passing this @Cats to the sp this will return no records.
also one more thing i am not in favor of that this query to be executed as dynamic query.