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 |
|
Zoroaster
Aged Yak Warrior
702 Posts |
Posted - 2007-09-07 : 16:33:55
|
This query uses a cursor to fetch a parameter and pass it to another Stored proc. Is there a straightforward way to do this without using a cursor?declare @deleteunassigned intdeclare cur_unassigned cursor for select distinct a.cust_cont_pkfrom cust_cont a, cont_fold_ass b (NOLOCK)where a.cust_cont_pk != b.CUST_CONT_PK open cur_unassignedfetch next from cur_unassigned into @deleteunassignedwhile @@fetch_status = 0begin exec spDeleteCustContbypk @deleteunassigned fetch next from cur_unassigned into @deleteunassignedendclose cur_unassigneddeallocate cur_unassignedGOdeclare @deleteunassigned intdeclare cur_unassignedcursor for SELECT DISTINCT a.cust_cont_pk FROM cust_cont a, cont_fold_ass b (NOLOCK) WHERE a.cust_cont_pk != b.CUST_CONT_PKopen cur_unassignedFETCH NEXT FROM cur_unassigned INTO @deleteunassignedwhile @@fetch_status = 0begin exec spDeleteCustContbypk @deleteunassigned FETCH NEXT FROM cur_unassigned INTO @deleteunassignedendclose cur_unassigneddeallocate cur_unassignedGO Future guru in the making. |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-09-07 : 17:00:34
|
If all you are doing is deleting all customers which does not exist in cont_fold_ass table, you can do it straightaway using Delete command.Delete afrom cust_cont a left join cont_fold_ass bon a.cust_cont_pk = b.CUST_CONT_PKwhere b.CUST_CONT_PK is NULL Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
Zoroaster
Aged Yak Warrior
702 Posts |
Posted - 2007-09-07 : 19:59:51
|
Yes, unfortunately there is more to it. The cust_cont table has referential constraints on multiple other tables. The stored procedure spDeleteCustContbyPK handles the delete. I suppose I could just modify the procedure to do the deletes. I think I have some ideas now of where to go with this at this point though, I will post again if I get stuck. Future guru in the making. |
 |
|
|
|
|
|