私のSQLクエリは以下のようなものです
if exists(select 1 from mytable2 T,mytable M where T.bookid=M.bookid)
begin
insert into books(col1,col2)
select col1,col2 from library
end
else
begin
insert into booknotfound
select col1,col2 from library
end
ライブラリがソーステーブルだとします。BookId が「mytable」に存在する場合にのみ、books テーブルに挿入します。それ以外の場合は、「booknotfound」テーブルに挿入します。上記のクエリは、books テーブルにレコードを挿入しますが、「booknotfound」テーブルには挿入しません。私がやりたいことは、「mytable2」の各レコードの bookid を探していることです。この方法は可能ですか?