私は以下のようなテーブル変数を持っています:
declare @countries table (countryId int)
5つのレコードがあります。
次のように、リスト内のcountryIdごとに個別の挿入ステートメントを作成する必要があります。
insert into Countries (ID) VALUES (countryId)
カーソルを使わずにそれはどのように可能でしょうか?
もっと簡単な方法はありますか?
私は以下のようなテーブル変数を持っています:
declare @countries table (countryId int)
5つのレコードがあります。
次のように、リスト内のcountryIdごとに個別の挿入ステートメントを作成する必要があります。
insert into Countries (ID) VALUES (countryId)
カーソルを使わずにそれはどのように可能でしょうか?
もっと簡単な方法はありますか?
insert ... select
代わりに使用できますinsert ... values
:
insert Countries
(ID)
select countryId
from @countries
insert into Countries (ID)
SELECT CountryId FROM @countries
http://www.sqlteam.com/article/using-select-to-insert-records
を使用しますINSERT INTO SELECT FROM
INSERT INTO Countries (ID)
SELECT countryID
FROM @countries