I have 10 tables named mytable_1,mytable_2,mytabl
and so on
with similar schemas..I want to insert similar data into
SOME of these tables based on a condition as you can see
in my below code..
i want to insert only into those tables based on the
value of the 'cell'column in tableb..for instance if the
cell=2 in tableb, then i need to insert the records only
in mytable_2 and NOT in any other table , if cell=3
then insert only into mytable_3 and so on...
Can anybody please re-write my code to get the
above result if possible ?
declare @i int
set @i = 1
declare @sql varchar(1000)
WHILE @i <=10
SET @sql = 'insert into mytable_'+cast(@i as varchar(2)) + ' select *
from tableb where cell =2 '
SET @i = @i +1