SQL Server - Selectively inserting fields into temp table

后端 未结 3 1399
独厮守ぢ
独厮守ぢ 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.

提交回复
热议问题