Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


how to loop and insert records


how to loop and insert records

Author
Message
Patrick.I
Patrick.I
SSC-Enthusiastic
SSC-Enthusiastic (128 reputation)SSC-Enthusiastic (128 reputation)SSC-Enthusiastic (128 reputation)SSC-Enthusiastic (128 reputation)SSC-Enthusiastic (128 reputation)SSC-Enthusiastic (128 reputation)SSC-Enthusiastic (128 reputation)SSC-Enthusiastic (128 reputation)

Group: General Forum Members
Points: 128 Visits: 255
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
SQLZ
SQLZ
SSC Eights!
SSC Eights! (874 reputation)SSC Eights! (874 reputation)SSC Eights! (874 reputation)SSC Eights! (874 reputation)SSC Eights! (874 reputation)SSC Eights! (874 reputation)SSC Eights! (874 reputation)SSC Eights! (874 reputation)

Group: General Forum Members
Points: 874 Visits: 940
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
Todd Engen
Todd Engen
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1083 Visits: 6336
In your example, what values did you use from table A and table C to generate table B?
shamshudheen
shamshudheen
SSC-Enthusiastic
SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)

Group: General Forum Members
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
Patrick.I
Patrick.I
SSC-Enthusiastic
SSC-Enthusiastic (128 reputation)SSC-Enthusiastic (128 reputation)SSC-Enthusiastic (128 reputation)SSC-Enthusiastic (128 reputation)SSC-Enthusiastic (128 reputation)SSC-Enthusiastic (128 reputation)SSC-Enthusiastic (128 reputation)SSC-Enthusiastic (128 reputation)

Group: General Forum Members
Points: 128 Visits: 255
thanks guys all fixed using cross joins
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search