SQL Server - Selectively inserting fields into temp table

后端 未结 3 1395
独厮守ぢ
独厮守ぢ 2021-01-15 16:34

I am executing a SP within a SP. The SP returns say 10 params. I am interested in only 5 of them. How do I insert only these 5 into the temp table.

The code I have s

相关标签:
3条回答
  • 2021-01-15 16:39

    Use OPENROWSET like so:

    Select 
           *
    from OPENROWSET('SQLOLEDB','Data Source=Server_name;Trusted_Connection=yes;
          Integrated Security=SSPI','Execute yourdb..get_orders')
    

    Now you can easily filter the resultset

    Select 
    employeeid,orderid,orderdate 
    from 
    
    OPENROWSET('SQLOLEDB','Data Source=Server_name;Trusted_Connection=yes;
           Integrated Security=SSPI','Execute yourdb..get_orders')
    
    where
           orderdate>='19960101' and orderdate<'19970101'
    

    You don't need to create a temp table and you also don't need to worry about the structure of the procedure.

    Found here

    EDIT: Final solution moved from comments after discussion.

    0 讨论(0)
  • 2021-01-15 16:51

    You can't. The table variable must match exactly the structure of waht is being returned.

    0 讨论(0)
  • 2021-01-15 17:01

    Put the result of getDetails into a tablevar that contains all of the return values, then do your insert off of the additional table.

    You might also check out this site for more information on how to share data between stored procedures.

    0 讨论(0)
提交回复
热议问题