Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

SQL: Using the colums returned by a stored procedure

  • 24-10-2012 10:54AM
    #1
    Registered Users, Registered Users 2 Posts: 7,546 ✭✭✭


    There is a stored procedure in the database im working on Sybase SQL

    The SP doesnt alot of calculations on multiple tables then does a select and displays the results from a temp table that it created.

    I would like to modify the results of what is returned to SUM and GROUP some columns.

    Is there a way to do this without modifying the actual stored procedure.

    obviously the below doesnt work but i think it gets across what im trying to do.
    
    SELECT col1, col2, SUM(col3) FROM
        CALL sp_myStoredProc()
    WHERE col1 = 1234
    GROUP BY col1, col2
    
    


Comments

  • Closed Accounts Posts: 3,357 ✭✭✭Beano


    I'm not a Sybase guy but the following works in SQL Server so may work for you. you can create a temp table and insert the results from the stored proc into that temp table. you can then do your grouping on the data in the temp table. Something like :

    create table #temp (id int, val varchar(100))
    insert into #temp
    exec sp_myStoredProc @value, @value, @value, @count OUTPUT


  • Registered Users, Registered Users 2 Posts: 7,546 ✭✭✭BrokenArrows


    Beano wrote: »
    I'm not a Sybase guy but the following works in SQL Server so may work for you. you can create a temp table and insert the results from the stored proc into that temp table. you can then do your grouping on the data in the temp table. Something like :

    create table #temp (id int, val varchar(100))
    insert into #temp
    exec sp_myStoredProc @value, @value, @value, @count OUTPUT

    Tried a few variations but no luck.


  • Closed Accounts Posts: 3,357 ✭✭✭Beano




  • Registered Users, Registered Users 2 Posts: 7,546 ✭✭✭BrokenArrows


    Ah finally got it working.

    I could have sworn i tried this before and it failed. Fairly simple.
    SELECT * from my_stored_proc() where xyz = 'asd'
    

    my mistake was i was using CALL when it wasnt needed.


Advertisement