0

我还是 SQL 的新手,所以通过学习来做到这一点。我想使用存储过程填充表。我的问题是如何调用该过程以便执行它并填充表格。到目前为止,我已经做到了。

ALTER proc [dbo].[MytestTableLoad]
   @ID int,
   @FirstName varchar,
As
Begin
   Set nocount on;

   merge dbo.MytestTable2 as target
   using (select @ID, @FirstName,@LastName) as source (Id, FirstName, LastName)
   on (target.Id=source.Id)
   when not matched then
     Insert   (Id, FirstName, LastName)
     values (@Id, @FirstName,@LastName)
   ;
END    
4

2 回答 2

1

更简单的语法是;

insert into table2
(field1, field2, etc)
select field1, field2, etc
from SomeOtherTables
where not exists
(subquery to check for records you don't want.)
于 2013-03-18T22:40:49.373 回答
0

"how do I call the procedure so that it gets executed and the table gets populated."

Like this:

EXEC MytestTableLoad 1,'Bob'
于 2013-03-18T23:12:11.970 回答