Solved

Help with Query Syntax for Update Query

Posted on 2014-07-31
2
235 Views
Last Modified: 2014-07-31
I am trying to update all of one field's table to another field's data based upon a link between the two tables.:

UPDATE CustSalesByPartPastYearTemp SET CustItem = (SELECT [CUST ITEM #] FROM [INVOICE DETAILS] INNER JOIN CustSalesByPartPastYearTemp ON [INVOICE DETAILS].[LINESERIAL#] = CustSalesByPartPastYearTemp.LineSerial)

Basically, I want the field CustItem in table CustSalesByPartPastYearTemp to equal what the field CUST ITEM # in the table INVOICE DETAILS is by linking the fields LineSerial and LINESERIAL#.

This gives an error saying :Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

I am attempting to run this on an .asp page, sql-2000 is the back end database.
0
Comment
Question by:dzirkelb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 1

Accepted Solution

by:
Dukster131 earned 500 total points
ID: 40231783
You should be able to do something like this if I understand you correctly

UPDATE  t
Set CustItem = [CUST ITEM #]
from CustSalesByPartPastYearTemp t
inner join [INVOICE DETAILS] d on t.CustItem = d.[CUST ITEM#]
INNER JOIN CustSalesByPartPastYearTemp p on p.LineSerial = d.[LINESERIAL#]
0
 

Author Comment

by:dzirkelb
ID: 40231903
Thanks.  Your post led me to the following working code:

UPDATE CustSalesByPartPastYearTemp SET CustItem = [CUST ITEM #] FROM CustSalesByPartPastYearTemp INNER JOIN [INVOICE DETAILS] on CustSalesByPartPastYearTemp.LineSerial = [INVOICE DETAILS].[LINESERIAL#]
0

Featured Post

Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question