Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

how to loop and insert records Expand / Collapse
Author
Message
Posted Tuesday, April 1, 2008 4:10 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, March 5, 2014 9:35 PM
Points: 119, Visits: 240
i have 3 tables like so below:

table -A
pid mid
--- ----
1 7
2 29

table -B
sid pid mid
--- --- ---
1 1 7
2 1 7
3 2 29

table -C
sid toy
--- ---
1 car
2 ball
3 toy phone

what i want is to loop through table A and C and add values sid,pid and mid into table -B
column sid,pid and mid in table -B isn't auto incremented

Any ideas and thanks in advance
Post #477489
Posted Tuesday, April 1, 2008 4:54 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Thursday, August 21, 2014 4:43 AM
Points: 870, Visits: 897
Hi Patrick,

I'm not sure you'd need to use a loop. Would a cross join not work?

select sid, pid, mid
from testA, TestC



Karl
source control for SQL Server
Post #477502
Posted Tuesday, April 1, 2008 5:02 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, November 12, 2013 8:44 AM
Points: 1,073, Visits: 6,334
In your example, what values did you use from table A and table C to generate table B?

Post #477507
Posted Thursday, April 3, 2008 12:57 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, June 10, 2009 10:50 PM
Points: 120, Visits: 211
Patrick Ige (4/1/2008)
i have 3 tables like so below:

table -A
pid mid
--- ----
1 7
2 29

table -B
sid pid mid
--- --- ---
1 1 7
2 1 7
3 2 29

table -C
sid toy
--- ---
1 car
2 ball
3 toy phone

what i want is to loop through table A and C and add values sid,pid and mid into table -B
column sid,pid and mid in table -B isn't auto incremented

Any ideas and thanks in advance


Patrick,

what is the relation between A and C table

if you do cross join you will get cortesan product records. check your resulted table

shamsudheen
Post #479000
Posted Thursday, April 3, 2008 3:32 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, March 5, 2014 9:35 PM
Points: 119, Visits: 240
thanks guys all fixed using cross joins
Post #479062
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse