Link to home
Start Free TrialLog in
Avatar of rgb192
rgb192Flag for United States of America

asked on

sql server for loop

INSERT INTO newTable
SELECT
(SELECT zip from orders where orderid = x ) as Zip,
(SELECT title from products where productid = x ) as Title,
(select description from accessory where accessoryid  = x ) as description

could this be put into a for loop and all the values of the table populated
Avatar of chapmandew
chapmandew
Flag of United States of America image

hmmm...are you wantin a list of all possible values from the tables in your new table?  if so, you can do this (without a loop)

select zip, title, description
from zip, products, accessory
where orderid= x and productid = x and accessoryid= x
can you give us more details?
table structures with sample data and what you want to do with the data?
Avatar of rgb192

ASKER

>>select zip, title, description
from zip, products, accessory
where orderid= x and productid = x and accessoryid= x


but x would be orderid
and orderid goes from 1 to 1000
THEN DESCRIBE YOUR PROBLEM BETTER.
can you provide us with the table structures along with the foreign key columns or relations between the tables marked?
Avatar of rgb192

ASKER

>>can you provide us with the table structures along with the foreign key columns or relations between the tables marked?

not sure
Tim out.
ASKER CERTIFIED SOLUTION
Avatar of HainKurt
HainKurt
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Can you provide sample set and expected result?
Avatar of rgb192

ASKER

thanks