Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
lols
Posting Yak Master
174 Posts |
Posted - 2007-08-28 : 02:16:24
|
| Hi, I have the following scenario :CustomerDetailcustomeridcustomernamestatusapp_no[status = 0 means customer virtually deleted] CustomerArchivearchiveno [autoincrement]customeridcustomernamestatus At the end of the month, I have to physically delete customers. I have written two stored procs: proc1create proc spoc_startdeletionasdeclare @app_no intselect @app_no = (select app_no from customerdetail where status=0)EXEC spoc_insertcustomerarchive @app_no-- After transferrin, physically deletedelete from customerdetail where status=0 proc2create proc spoc_insertcustomerarchive@app_no intasinsert into customerarchive(customerid,customername,status)select customerid,customername,status from customerdetail where app_no = @app_no It works fine if there is only one row with status=0, however the problem is that when there are multiple rows in customerdetail with status=0, it returns 'Subquery returned more than one value'How can i transfer multiple rows one by one from the customerdetail to customerarchive using the same procs and then delete the rows once they are transferred.I know i need to loop somehow but am not sure how to do it. Can you help me with some code. |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-08-28 : 02:47:55
|
| You dont need two procedures. Use only second with the codecreate proc spoc_insertcustomerarchiveasinsert into customerarchive(customerid,customername,status)select customerid,customername,status from customerdetail where status=0delete from customerdetail where status=0 If you cant edit the procedure, then create new procedure with the aboce codeMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|