473,396 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Having problem with Update from query

Hey guys,

I'm trying to update some columns in a table using another table's data but there seems to be some problem due to join among the two tables. Here is my query
Expand|Select|Wrap|Line Numbers
  1. Update DMM_SalesReporting..sapis_test
  2.         SET     Claims_Qty = ISNULL(Claims_Qty, 0) 
  3.                  + CONVERT(varchar(30), b.BaseUOMQuantity),
  4.             Claims_Dollars = ISNULL(Claims_Dollars, 0) 
  5.                  + b.BaseUOMAmount,
  6.             Update_DateTime = getdate(), MM_Batch_Num = convert(varchar(30), b.MM_Batch_Num)        
  7.         FROM DMM_SalesReporting..sapis_test a, Buckets_Staging b 
  8.         WHERE     b.bucket = 'Claims' and a.Month_Key = b.Month_key and 
  9.             a.sku_wid = convert(varchar(10), b.FromSku_wid) and 
  10.             a.Plant_wid = convert(varchar(10), b.FromPlant_wid) and a.PlantFlag = b.PlantFlag
  11.  
Currently, the data that i'm working with, there are only 9 records in table Bucket_Staging, which are associated with Bucket = Claims. However, when i run this query it updates 33 records. I ran a SELECT query to check few things and realized that it is updating some records multiple times. So i was wondering if there's a way around this problem because i need to keep track of number of records failed and updated successfully.

Thanking in advance!
Feb 4 '08 #1
4 1514
code green
1,726 Expert 1GB
there are only 9 records in table Bucket_Staging, However, when i run this query it updates 33 records
Impossible if there are only nine records!
I ran a SELECT query to check few things
What things?
and realized that it is updating some records multiple times.
How do you know this?
because i need to keep track of number of records failed and updated successfully
Understable, But how are you doing this?
Feb 4 '08 #2
Impossible if there are only nine records!
Please see the following screen-shot



How do you know this?
Please see the difference yourself






Understable, But how are you doing this?
I first count number of records in the table for each bucket and then use the value of @@ROWCOUNT to determine the number of failed records.
Feb 4 '08 #3
ck9663
2,878 Expert 2GB
Please see the following screen-shot



Please see the difference yourself






I first count number of records in the table for each bucket and then use the value of @@ROWCOUNT to determine the number of failed records.

you have duplicate records... you might want to clean your table first

-- ck
Feb 4 '08 #4
code green
1,726 Expert 1GB
you have duplicate records... you might want to clean your table first
Well done ck9663. Never thought of that!
Feb 5 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Bill Clark | last post by:
I have about 20,000 records pulled from Excel that I need to update. What I need to do is run an update query that bascially says: If a field is null, update it with the previous record value of...
9
by: James Butler | last post by:
Our setup: Online db: MySQL Inhouse db: MS Access 97 with MySQL tables linked via ODBC Our issue: Almost every field updates successfully, except one. A scenario: Information is written to...
1
by: beil.jp | last post by:
Hi All - I'm new to Google Groups and just a novice user of Access, so please forgive me if my question is elementary: I am having a problem using the "update query" for my first time. In my...
0
by: harry12 | last post by:
Hello- I'm fairly new at using Microsoft Access and I'm having trouble getting a couple of things to work in my database. The first is that I have yet to find a way to get an append query to...
2
by: underground | last post by:
Hi, everyone I've been trying to figure out a way for a user to update there information. I'm using sections to identify the specific user..Here is the form <? include("include/session.php");...
16
by: ARC | last post by:
Hello all, So I'm knee deep in this import utility program, and am coming up with all sorts of "gotcha's!". 1st off. On a "Find Duplicates Query", does anyone have a good solution for...
3
by: nitinpatel1117 | last post by:
Hi, I've got a slight issue which i'm trying to resolve and was wondering if anyone would help. Basically, I was building a web application, and while it was being built I was connecting to...
4
by: raghuvendra | last post by:
Hi I have a jsp page with 4 columns: namely Category name , Category order, Input field and a submit button. All these are aligned in a row. And Each Category Name has its corresponding Category...
5
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.