Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Converting array of strings into integer to pass into a where clause

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-05-06 : 14:29:22
SAM writes "The GUI sends a selection list from a listbox. The choice can be All (0) or aaa(1), bbb(2), ccc(3), ddd(4). I will receive the list into the SP as '1,2,3,4' or '1' or '1,2' or '0' (depending on the user selection)

I took the code suggested by Mr. Graz code for parsing the array in the SP. If you look at the sample SP below: I have to build the WHERE clause with an IN statement. How do i do that?? Thanks for your input.

CREATE procedure testarray
@aPackState varchar(10),
@separator char(1) =','
AS
BEGIN
declare @aPackstate_value varchar(10)
declare @iPackState int
declare @separator_position int
set @aPackState = @aPackState + @separator
WHILE patindex ('%' + @separator + '%' ,@aPackState) <> 0
BEGIN
select @separator_position =
patindex ('%' + @separator + '%' ,@aPackState)
select @aPackstate_value =
left@aPackState,@separator_position - 1)

select @iPackState = @aPackState_value

IF @iPackState = 0 THEN
select ipackstatex,description from ipackstate
where ipackstatex = @iPackState
ELSE
select ipackstatex, description from ipackstate
where ipackstatex in (1,2,3,4) -- THIS IS WHAT I WANT
select @aPackState =
stuff(@aPackState, 1, @separator_position, '')
END
END"
   

- Advertisement -