Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2004
    Posts
    32

    Unanswered: select from a stored procedure?

    Hey all! I have a quick question. Is it possible do formulate a select query where one of the tables is a recordset returned from a stored procedure? If so, what's the syntax?

    In other words, if I have a stored proc whose last command is:

    select t.[Region_Code],
    t.[Country_Code],
    sum([Total]) as [Total]
    from #tmp t
    group by [Region_Code],
    [Country_Code]
    order by [Region_Code],
    [Country_Code]

    Then can I somehow get a handle on that cursor and join it to another table etc? Thanks!

  2. #2
    Join Date
    Jan 2004
    Posts
    32
    Aha! Apparently I can do this with openrowset but I am using windows authentication and anyways dont want to hardcore logins and passwords for my DB. I've never used openrowset, can I use it specifying the current database and forego having to enter security credentials?

  3. #3
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    No..but you could put the results of an execution in to a table then join to that

    INSERT INTO myTable99(col list) EXEC sproc
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  4. #4
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    ...or rewrite your stored procedure as a User-defined table function. Then it is easy use it in a select statement.
    If it's not practically useful, then it's practically useless.

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

  5. #5
    Join Date
    Jan 2004
    Posts
    32
    Yah I thought of that except that the existing proc uses a TON of temp tables which apparently you cannot use in a function

  6. #6
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    OK, so do what I suggested.....
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

Posting Permissions

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