Hi there..
I am trying to write an SQL report that takes a user defined variable as a filter (WHERE) clause.
the user inputs the criteria that they want to search for in a delimited string.
I need to understand the best way to identify the number of criteria that the user has specified, and then pass these criteria to another query to be placed in the WHERE clause.
I have the following code already, I just need to find out how to loop this until the end of the string so that I can append to another query..
Thanks in adv.
I am trying to write an SQL report that takes a user defined variable as a filter (WHERE) clause.
the user inputs the criteria that they want to search for in a delimited string.
I need to understand the best way to identify the number of criteria that the user has specified, and then pass these criteria to another query to be placed in the WHERE clause.
I have the following code already, I just need to find out how to loop this until the end of the string so that I can append to another query..
Code:
declare @var varchar(255)
declare @IDLen int
declare @Delim int
declare @NumPatch int
SET @Var = 'ms04-007;ms04-008;ms05-001;ms05-004'
set @idlen = 8
set @delim = charindex(';',@var)
set @numpatch = len(@var)/@idlen
print @delim -- delim char position
print @numpatch -- number of variables in the string
print substring(@var, 1, @delim -1) -- the first variable
set @var = substring(@var, @delim +1, len(@var)) -- reset the string var
print @var -- remainder
Thanks in adv.