rgb192
asked on
sql insert variable
would like for x to start at 1 and go to 5
this works
declare @x int
set @x = 1
INSERT INTO information
SELECT
(SELECT productid from products where productid = @x ),
(select accessoryorder from accessorytypes where accessoryid = @x ),
(SELECT orderid from orders where orderid = @x )
select * from information
this works
declare @x int
set @x = 1
INSERT INTO information
SELECT
(SELECT productid from products where productid = @x ),
(select accessoryorder from accessorytypes where accessoryid = @x ),
(SELECT orderid from orders where orderid = @x )
select * from information
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
declare @x int
set @x = 1
while @x < 5
BEGIN
INSERT INTO information
SELECT productid from products p
join accessorytypes a on p.productid = a.accessoryid
join orders o on a.accessoryid = o.orderid
where productid = @x
set @x = @x + 1
END
set @x = 1
while @x < 5
BEGIN
INSERT INTO information
SELECT productid from products p
join accessorytypes a on p.productid = a.accessoryid
join orders o on a.accessoryid = o.orderid
where productid = @x
set @x = @x + 1
END
declare @x int
set @x = 1
while @x < 5
BEGIN
INSERT INTO information
SELECT productid, accessoryorder , orderid from products p
join accessorytypes a on p.productid = a.accessoryid
join orders o on a.accessoryid = o.orderid
where productid = @x
set @x = @x + 1
END
set @x = 1
while @x < 5
BEGIN
INSERT INTO information
SELECT productid, accessoryorder , orderid from products p
join accessorytypes a on p.productid = a.accessoryid
join orders o on a.accessoryid = o.orderid
where productid = @x
set @x = @x + 1
END
ASKER
thanks
set @x = 1
while @x < 5
BEGIN
INSERT INTO information
SELECT productid from products p
join accessorytypes a on p.productid = a.accessoryid
join orders o on a.accessoryid = o.orderid
where productid = @x
END