Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

SQL: Using the colums returned by a stored procedure

Options
  • 24-10-2012 11:54am
    #1
    Registered Users Posts: 7,501 ✭✭✭


    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 Posts: 7,501 ✭✭✭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 Posts: 7,501 ✭✭✭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