|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
Loops inside a stored procedure
I need to know how to loop through the results of a select inside a stored procedure and execute inserts. The following is the pseudo code.
Code:
for each row in table t1 {
select the ID from t1
insert the ID into table t2
}
Thanks. Last edited by mark_thurston : March 25th, 2004 at 04:03 PM. Reason: formatting |
|
#2
|
|||
|
|||
|
You don't need a loop
Code:
insert into t2(id) select id from t1 |
|
#3
|
|||
|
|||
|
Loops inside a stored procedure
I guess that I over-simplified the code. In the loop I need to get a couple of fields from t1 and do a like command on them.
Code:
for each row in table t1 {
select the t2.ID from t2 where t2.textValue like '%' + t1.textValue + '%'
insert the t2.ID into table t3
}
Sorry for the previous ambiguity. |
|
#4
|
|||
|
|||
|
You don't need a loop
Code:
insert into t3(id) select id from t2
where exists (select * from t1
where t2.textvalue like '%' + t1.textValue + '%')
|
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > Loops inside a stored procedure |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|