Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2003
    Location
    UK(berkshire)
    Posts
    11

    Unanswered: Stored Proc In Query

    Hi

    I would like to write a query, where I would like to pass in a string value into proc, which is comma delimited, ie

    create proc spName
    @list as varchar(4000)
    as
    ....
    ....
    ....


    Then I wish to iterate through the string running a query for each item in the list.

    Do I place values in @list into a cursor ?
    Thanks

    youeee

  2. #2
    Join Date
    Jan 2004
    Posts
    49

  3. #3
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    I think that I just posted what you need in another thread here.

    -PatP

  4. #4
    Join Date
    Jul 2002
    Location
    Village, MD
    Posts
    621
    Try this:

    alter proc test(@line varchar(6000))
    as
    set nocount on
    declare @step varchar(200)

    while charindex(',',@line)>0 begin
    select @step=left(@line,charindex(',',@line)-1)
    select @step
    -- do something with it
    select @line=right(@line,(len(@line)-charindex(',',@line)))
    end
    go
    test '1,2,3,4,'

Posting Permissions

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