March 27, 2011 at 1:31 pm
hmbtx (3/27/2011)
Ron:Yes, Craig's code satisfied my requirements?
If it is okay, I would like to add one additional question based on Craig's solution and that is how can I change the script so that it will correct the regsiter_count in A_Header.
Example: Update A_Header set A_Header.register_count = drv.line_count.
Thanks
Howard
Like so: 🙂
UPDATE a
SET
register_count = drv.line_count
FROM
A_Header AS a
JOIN
( SELECT ali.Activity_Code, COUNT(*) AS line_count
FROM A_Line AS ali
GROUP BY ali.Activity_code
) AS drv
ON a.activity_code = drv.activity_code
where
drv.line_count <> a.register_count
Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.
For better assistance in answering your questions[/url] | Forum Netiquette
For index/tuning help, follow these directions.[/url] |Tally Tables[/url]
Twitter: @AnyWayDBA
March 27, 2011 at 1:46 pm
Craig:
Thanks. The script worked just fine.
Am I correct that your original script that listed the counts in error cannot also correct the count?
Put another way, is there a way to list the rows with an error count and also correct the error count in the same script?
Howard
March 27, 2011 at 2:45 pm
hmbtx (3/27/2011)
Craig:Thanks. The script worked just fine.
Am I correct that your original script that listed the counts in error cannot also correct the count?
Put another way, is there a way to list the rows with an error count and also correct the error count in the same script?
Howard
Look into the OUTPUT clause, it will show you how to get the results from what you actually modified in a single statement.
Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.
For better assistance in answering your questions[/url] | Forum Netiquette
For index/tuning help, follow these directions.[/url] |Tally Tables[/url]
Twitter: @AnyWayDBA
March 27, 2011 at 3:44 pm
Craig:
Thanks for everything. You have been a great help.
Howard
March 27, 2011 at 5:46 pm
Craig Farrell (3/27/2011)
Look into the OUTPUT clause...
Isn't this an SQL Server 2000 post? 🙂
--Jeff Moden
Change is inevitable... Change for the better is not.
March 27, 2011 at 7:22 pm
Jeff:
Yes, this is an SQL 2000 post.
I incorrectly posted it to the wrong forum.
I apologize for that.
Howard
March 27, 2011 at 8:20 pm
Jeff Moden (3/27/2011)
Craig Farrell (3/27/2011)
Look into the OUTPUT clause...Isn't this an SQL Server 2000 post? 🙂
Daaammmiiittt... you're right, Jeff... and I pointed that out in the first place! D'oh.
OUTPUT not available, errrr... hmmm... no, not really. Do your select into a #tbl, then do your update... it's really the only way that doesn't open up other cans of worms.
Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.
For better assistance in answering your questions[/url] | Forum Netiquette
For index/tuning help, follow these directions.[/url] |Tally Tables[/url]
Twitter: @AnyWayDBA
March 28, 2011 at 12:02 am
See? I do pay attention once in a while. 😛
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 8 posts - 16 through 22 (of 22 total)
You must be logged in to reply to this topic. Login to reply