最初,我将使用存储过程(SP1)将源表的所有列存储到单个变量中。此 SP1 在 SP2 中调用,该变量插入到目标表中。
我知道这种方法,但坚持实施它。
-- SP1
Create procedure insert_data
AS
Declare @data nvarchar(60)
Begin
EXEC get
--Here i have to insert
END
Go
--SP2
Create procedure get_column
AS
Declare
@e_id int , @e_name nvarchar(20) , @d_id int,@res nvarchar(50)
Begin
SET @e_id =(select Emp_ID from Dim_Employee where Emp_Name='Cathy');
SET @e_name =(select Emp_Name from Dim_Employee where emp_id=101);
SET @d_id =(select Dept_ID from Dim_Employee where emp_name='Cathy');
SET @res ='@e_id , @e_name , @d_id';
return @res
END
Go
如果您已经有目标表:
insert into DestTbl(emp_id, dept_id, ...)
select emp_id, dept_id, ...
from Dim_Employee d
where ...
如果您不这样做并希望创建它
select emp_id, dept_id, ...
into DestTbl
from Dim_Employee d
where ...
如果仍要使用变量
insert into DestTbl(emp_id, dept_id)
values (@emp_id, @dept_id, ...)
这是你要的吗?
插入 msdn 上的语句:https://technet.microsoft.com/en-us/library/ms174335.aspx