Solved

Help with Query Syntax for Update Query

Posted on 2014-07-31
2
227 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
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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

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…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how the fundamental information of how to create a table.

773 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