SQL server stored procedure return a table

后端 未结 9 2207
情书的邮戳
情书的邮戳 2020-12-04 19:39

I have a stored procedure that takes in two parameters. I can execute it successfully in Server Management Studio. It shows me the results which are as I expect. However it

9条回答
  •  失恋的感觉
    2020-12-04 20:12

    A procedure can't return a table as such. However you can select from a table in a procedure and direct it into a table (or table variable) like this:

    create procedure p_x
    as
    begin
    declare @t table(col1 varchar(10), col2 float, col3 float, col4 float)
    insert @t values('a', 1,1,1)
    insert @t values('b', 2,2,2)
    
    select * from @t
    end
    go
    
    declare @t table(col1 varchar(10), col2 float, col3 float, col4 float)
    insert @t
    exec p_x
    
    select * from @t
    

提交回复
热议问题