0

Thanks for all your help.

I am using SQL Server 2008 R2, my requirement is I need to insert stored procedure output into a new table (not temp or virtual table) in database with 2 additional columns without values to be added.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
rajeshnrh
  • 55
  • 1
  • 3
  • 9

2 Answers2

0

This is an example;

create procedure proc_1
as begin
    SELECT name, database_id FROM sys.databases
end;
go

create table new_tbl (
    name varchar(150),
    id int,
    new_col1 int,
    new_col2 int
)
go

declare @tab table(
    name varchar(150),
    id int  
)
begin
    insert into @tab
    exec proc_1

    insert into new_tbl
    select name, id, 1, 2 from @tab;
end;
go

select * from new_tbl

OutPut:
master  1   1   2
tempdb  2   1   2
model   3   1   2
......
Praveen
  • 8,945
  • 4
  • 31
  • 49
0

Create a stored procedure which will give default columns as output. for example:

CREATE Procedure proc1
AS 
BEGIN
    SELECT name, database_id,1 as Col1,2 as Col2
    FROM sys.databases
END;
go

output of above SP will provide the 2 aditional columns needed.

Biswabid
  • 1,378
  • 11
  • 26