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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 "where exists" doesn't do what I think it should..

Author  Topic 

aclarke
Posting Yak Master

133 Posts

Posted - 2001-08-23 : 14:23:50
Hi. I wrote some pretty fancy code that used a cursor within a cursor to update a database table. This took my computer over an hour to run and I have to do it quite often. After reading all the cursor hate mail on this site I thought I'd try to rewrite it without a cursor. I'll post the before and after code below, but basically I have this scenario. I have an orders_lineItem table (quorters_lineItem) that contains, well, items that have been ordered. Some items are parents, some are subordinates. So if you buy a parent item (the shopping cart automatically adds some subordinate items). Before, it only added subordinate items if the customer had changed the quantity from default. I'm going back now and changing the way it works so this table stores ALL the subordinate items. So I have to go through and for each order, get the subordinate items for each parent item, plus the quantity, ratio, etc., then put the subordinate item into the quorter_lineItem table IF IT ISN'T THERE ALREADY. But my "where not exists" in my new code doesn't stop the query from pulling back ALL the subordinate line items, even the ones that the custome already has in their cart. I've been messing with this for several hours and it's getting quite frustrating...

Hmm I've previewed this and it looks like I'm being concatenated. I'll put the code in separate postings.

   

- Advertisement -