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
 General SQL Server Forums
 New to SQL Server Programming
 Problem with Update

Author  Topic 

Vack
Aged Yak Warrior

530 Posts

Posted - 2008-09-09 : 14:55:25
Have the following script that keeps subtracting from my amount each time I run the script when I only want to run it once.

bdr_hfl is my amount.
I'm going to add a Posted flag to freefield4 which I think is going to solve my problem. So would I just add another clause in my where statement below?

where freefield4 = 'N'



begin
UPDATE e
SET e.bdr_hfl = e.bdr_hfl - d.x
FROM gbkmut AS e
INNER JOIN (
SELECT faktuurnr,
SUM(bdr_hfl) AS x
FROM gbkmut
WHERE freefield3 = 'Rebate'
GROUP BY faktuurnr
) AS d ON d.faktuurnr = e.faktuurnr
WHERE e.reknr = ' 12001'
end

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2008-09-09 : 16:32:14
Not sure what your question is.

>>Have the following script that keeps subtracting from my amount each time I run the script when I only want to run it once.
If you only want to run it once than why do you keep running it?

Be One with the Optimizer
TG
Go to Top of Page

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2008-09-10 : 01:49:24
Is you issue that this code is part of a larger workflow.? If that is the case , set up a separate query that checks for your conditions , and then decide if you are to run the code.

Jack Vamvas
--------------------
Search IT jobs from multiple sources- http://www.ITjobfeed.com
Go to Top of Page
   

- Advertisement -