Results 1 to 2 of 2
  1. #1
    Join Date
    May 2008
    Posts
    2

    Unanswered: Stored procedure question

    Hi,

    I'd like to output the result from a query in a stored procedure.
    The challenge is that the result from the query is unknown, so i'd like to iterate through the returned rows and output each field dynamically.
    example:

    if object_id('dbo.create_insert') is not null
    drop procedure dbo.create_insert
    go
    create procedure dbo.create_insert(
    @birthdate int
    , @personnr int
    , @tablename varchar(8)
    )
    as

    declare cur_create_insert cursor for
    select *
    from @tablename
    where birthdate = @birthdate
    and personnr = @personnr


    And now!
    open cursor cur_create_insert
    while (result has more rows)
    while (there are more columns)
    print column


    Is this possible?

    -Thomas

  2. #2
    Join Date
    Nov 2006
    Posts
    4

    try this

    You can do it inside another stored proc

    some thing like this
    create proc test
    as
    declare @name

    declare test1_cursor cursor for
    select name from table

    open test1_cursor

    fetch test1_cursor into @name

    while @@sqlstatus=0
    begin

    exec your_proc @name

    fetch test1_cursor into @name

    end

    close test1_cursor

    deallocate cursor test1_cursor

Posting Permissions

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