我想在相同條件(WHERE子句)每個delete語句刪除多個表中的數據。聲明在SQL Server存儲過程變量列表
delete from tblA where id in (select x.id from tblX x where name like N'%test%')
delete from tblB where id in (select x.id from tblX x where name like N'%test%')
delete from tblC where id in (select x.id from tblX x where name like N'%test%')
delete from tblD where id in (select x.id from tblX x where name like N'%test%')
有沒有辦法從上面的select語句中聲明一個存儲id的列表?
我想:
declare @ids int
set @ids = select x.id from tblX x where name like N'%test%'
但抱怨
子查詢返回多個值。這是在子查詢 如下時不允許=,!=,<,< =,>,> =,或當子查詢用作 的表達式。
請指教,謝謝。
想想爲什麼排名前1的人會這樣做。 http://stackoverflow.com/questions/11232751/sql-error-subquery-returned-more-than-1-value – Tim 2013-02-22 19:00:17