| Author |
Topic |
|
esthera
Master Smack Fu Yak Hacker
1410 Posts |
Posted - 2007-03-07 : 10:09:38
|
| i'm trying to do the following in a stored procedure can you help mei have a @reg which has the reg codei want to select all records from tempcustomers where reg=@reg and move those records to customers adding on 2 fields (date and batch)can you help me with the syntax? how can i loop through a table moving it in sql? |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-03-07 : 10:13:39
|
move as in INSERT or UPDATE ? KH |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-03-07 : 10:29:26
|
| [code]Declare @dt datetime, @batch intselect @dt = getdate(), @batch = 1 -- set desired values hereInsert customers(col1, col2, [date], batch)Select col1, col2, @dt, @batchFrom tempcustomerswhere reg=@reg[/code]Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
esthera
Master Smack Fu Yak Hacker
1410 Posts |
Posted - 2007-03-07 : 11:06:50
|
| this will loop thorugh and do all those with that reg? (even if there is more then one?also I waanted to move not copy so how do I insert and then delete that record? |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-03-07 : 11:14:30
|
| Yes it will move all records. If you want to delete those records from original table, add delete statement after insert with same WHERE clause. And be sure to put both of them inside transaction !Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
esthera
Master Smack Fu Yak Hacker
1410 Posts |
Posted - 2007-03-07 : 12:13:20
|
| so can i update the record in tempcustomers so i know that i moved it? |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
esthera
Master Smack Fu Yak Hacker
1410 Posts |
Posted - 2007-03-07 : 12:26:48
|
| yes so how do i update a status collumn at the same time as movingInsert customers(col1, col2, [date], batch)Select col1, col2, @dt, @batchFrom tempcustomerswhere reg=@reg |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
|