I tried searching and couldn't really find an answer to what I needed, so here goes:
I've got a field called type_list that is being passed into a cursor. This field is varchar and can contain single values or unlimited values seperated by a comma, like this: 1,2,3 . I then need to be able to pass that cursor value into a where clause for a statement, something like this: select * from table1 where type in ('1', '2', '3'). I'm trying to write something that parses the field while being dynamically based on the number of commas. If anyone can point me in the proper direction, I would really appreciate it.
maybe this explains it a little more clearly:
declare @list varchar(100)
set @list = '1,2,3,4'
--missing code to transform to proper form --
select * from table1 where type in @list
which needs to look like
select * from table1 where type in ('1','2','3','4') when it's done.
thanks in advance
-Dan
I've got a field called type_list that is being passed into a cursor. This field is varchar and can contain single values or unlimited values seperated by a comma, like this: 1,2,3 . I then need to be able to pass that cursor value into a where clause for a statement, something like this: select * from table1 where type in ('1', '2', '3'). I'm trying to write something that parses the field while being dynamically based on the number of commas. If anyone can point me in the proper direction, I would really appreciate it.
maybe this explains it a little more clearly:
declare @list varchar(100)
set @list = '1,2,3,4'
--missing code to transform to proper form --
select * from table1 where type in @list
which needs to look like
select * from table1 where type in ('1','2','3','4') when it's done.
thanks in advance
-Dan