SQL Server : Insert statement Multiple values when 1 value stays the same untill all values inserted -
i want following:
i have table has columns:
id, manufacturerretailerid, categoryid, order order can null.
in manufacturerretailerid , categoryid need following...
if manufacturerretailer exists in manufacturerretailer table insert categoryids:
1 2 3 4 5
so need list of manufacturerretailerids:
select * manufacturerretailers mr join manufacturers m on m.id = mr.manufacturerid m.id = 14 for each of ids need insert categoryids.
i've started with:
insert manufacturerretailercategories (manufacturerretailerid, categoryid) select mr.id manufacturerretailers mr join manufacturers m on m.id = mr.manufacturerid m.id = 14 but i'm not sure how insert each manufacturerretailerid 1,2,3,4,5 in categoryid field.
so following:
manufactureretailerids - 10,20,30,40,50
i want following:
manufacturerretailerid categoryid 10 1 10 2 10 3 10 4 10 5 20 1 20 2 20 3 20 4 20 5 and on...
the actual categoryid list 30 long want know if possible in 1 insert statement.
any appreciated.
thanks,
edit:
i think add 1 value in:
insert manufacturerretailercategories (manufacturerretailerid, categoryid) values((select mr.id manufacturerretailers mr join manufacturers m on m.id = mr.manufacturerid m.id = 14) ,(1)) but i'd know how add many
the category ids list of ids - @ moment there not relationship can t pull them table.
i think can want cross join. question not clear category values located. may want:
insert manufacturerretailercategories (manufacturerretailerid, categoryid) select mr.id, c.categoryid manufacturerretailers mr join manufacturers m on m.id = mr.manufacturerid cross join (select distinct categoryid manufacturerretailers) c m.id = 14 ; if have explicit table of categories, should use instead of subquery.
Comments
Post a Comment