I'd like to delete data from multiple tables with the same conditions (where clause) for each delete statement.
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%')
Is there a way to declare a list that stores the ids from the select statement above?
I tried:
declare @ids int
set @ids = select x.id from tblX x where name like N'%test%'
But it complains that
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
Please advise, thanks.