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
 Transact-SQL (2000)
 Delete problem

Author  Topic 

Rauken
Posting Yak Master

108 Posts

Posted - 2005-06-28 : 06:18:34
Hi!

Let me first try to explain my problem. I'm from Sweden so I try to explain it as general and simple as possible.

I get invoices from different gas companies like Chevron. I import these invoices into a financial system. The invoices comes in semi-colon separated textfiles. I begin to import them into a table that matches the textfile. From there I run a cursor on the table and goes through each record and I might check if the article that is bought is valid for example gas, oil is valid, a new car radio is not.

Sometimes and article is entered, then the clerk change their mind and has to enter a negative amount on the same article. Then.. they might change their mind again and enters the article.

What I want to do is to remove all the negative amounts and the matching positive amount.

After importing the file into the first table it looks something like this:


LicenseNo BuyDate BuyTime Ind Amount ArtNo
ABC 123 6/27/5 9.34 + 205 234
ABC 123 6/27/5 9.34 - 205 234
ABC 123 6/27/5 9.34 + 87 466
ABC 123 6/27/5 9.34 + 205 234


What I want to do is to remove the first two rows that takes out each other. The last one is ok.

I ran into the problem that SQL Server doesn't know which of the rows to remove because they are identical. There are many more fields but they are also identical so I can't find a way to identify each row.

Please ask if you need more info to solve the problem.

AndyB13
Aged Yak Warrior

583 Posts

Posted - 2005-06-28 : 07:06:48
Have a look at this article
http://www.sqlteam.com/item.asp?ItemID=3331

This should help get you started

Andy

Beauty is in the eyes of the beerholder
Go to Top of Page
   

- Advertisement -