Calling a SP in a SQL Statement

  • I have a SP that has 3 parameters

    getservicecontractsinfo 'ALL', '2009-09-01', '2009-09-30'

    I want to call this SP in a SQL statement so that I could filter the data or sort data...

    Thanks

  • You can insert the results into a table and then work with the table.

    CREATE TABLE x(

    the fields and datatypes your sp returns...

    )

    INSERT INTO x(fields)

    EXEC getservicecontractsinfo 'ALL', '2009-09-01', '2009-09-30'

    SELECT ...

    FROM x

    WHERE ...

    ORDER BY ...

    Seth Phelabaum


    Consistency is only a virtue if you're not a screwup. 😉

    Links: How to Post Sample Data[/url] :: Running Totals[/url] :: Tally Table[/url] :: Cross Tabs/Pivots[/url] :: String Concatenation[/url]

  • Another alternative is to rewrite your stored procedure as a table-valued function.

    select * from dbo.tfn_YourFunction(parm1,parm2,parm3)

    __________________________________________________

    Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
    Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply