Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2004
    Posts
    74

    Unanswered: Passing multiple selections to a stored proc parameter

    Hi,

    I am currently in the process of building a stored procedure that needs the ability to be passed one, multiple or all fields selected from a list box to each of the parameters of the stored procedure. I am currently using code similar to this below to accomplish this for each parameter:

    CREATE FUNCTION dbo.SplitOrderIDs
    (
    @OrderList varchar(500)
    )
    RETURNS
    @ParsedList table
    (
    OrderID int
    )
    AS
    BEGIN
    DECLARE @OrderID varchar(10), @Pos int

    SET @OrderList = LTRIM(RTRIM(@OrderList))+ ','
    SET @Pos = CHARINDEX(',', @OrderList, 1)

    IF REPLACE(@OrderList, ',', '') <> ''
    BEGIN
    WHILE @Pos > 0
    BEGIN
    SET @OrderID = LTRIM(RTRIM(LEFT(@OrderList, @Pos - 1)))
    IF @OrderID <> ''
    BEGIN
    INSERT INTO @ParsedList (OrderID)
    VALUES (CAST(@OrderID AS int)) --Use Appropriate conversion
    END
    SET @OrderList = RIGHT(@OrderList, LEN(@OrderList) - @Pos)
    SET @Pos = CHARINDEX(',', @OrderList, 1)

    END
    END
    RETURN
    END
    GO



    I have it working fine for the single or multiple selection, the trouble is that an 'All' selection needs to be in the list box as well, but I can't seem to get it working for this.

    Any suggestions?

    Thanks

    My plan is to have the same ability as under the 'Optional' section of this page:

    http://search1.workopolis.com/jobsho...ork.search_cri

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    I see you parsing the list, but I don't see where you select any records based upon it. So where would your ALL logic be incorporated?
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •