473,401 Members | 2,146 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,401 software developers and data experts.

UPDATE from Sub-select problem

Hello all,

i have a process which reads 2 csv files into two different tables (thus there is no real primary key etc)

i need to update 1 column in one table (EnterpriseBuffer) with data from another table (EnterpriseProdGroupToAnalystDeptMap.AnalystDepart ment). This is done where EnterpriseBuffer.PG = EnterpriseProdGroupToAnalystDeptMap.EnterprisePG.

I attempted the following:

Expand|Select|Wrap|Line Numbers
  1. Update EnterpriseBuffer SET EnterpriseBuffer.AnalystDepartment = 
  2. (SELECT dbo.EnterpriseProdGroupToAnalystDeptMap.AnalystDepartment 
  3. FROM EnterpriseBuffer LEFT OUTER JOIN dbo.EnterpriseProdGroupToAnalystDeptMap ON dbo.[EnterpriseBuffer ].PG = dbo.EnterpriseProdGroupToAnalystDeptMap.EnterprisePG)
  4. WHERE EnterpriseBuffer.PIPCode NOT IN (select buyingcode from AnalystBuffer)
However this fails due to:

Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
now i understand why this occurs, as the sub select returns 10700 rows, the same as a select * from EnterpriseBuffer would return. i just need to update analystdepartment column for each row in EnterpriseBuffer with the EnterpriseBuffer version in EnterpriseProdGroupToAnalystDeptMap.

This sounds very coimplicating i know, but please, any information or resolution to this would be helpful.
Nov 21 '07 #1
2 1528
deepuv04
227 Expert 100+
Hello all,

i have a process which reads 2 csv files into two different tables (thus there is no real primary key etc)

i need to update 1 column in one table (EnterpriseBuffer) with data from another table (EnterpriseProdGroupToAnalystDeptMap.AnalystDepart ment). This is done where EnterpriseBuffer.PG = EnterpriseProdGroupToAnalystDeptMap.EnterprisePG.

I attempted the following:

Expand|Select|Wrap|Line Numbers
  1. Update EnterpriseBuffer SET EnterpriseBuffer.AnalystDepartment = 
  2. (SELECT dbo.EnterpriseProdGroupToAnalystDeptMap.AnalystDepartment 
  3. FROM EnterpriseBuffer LEFT OUTER JOIN dbo.EnterpriseProdGroupToAnalystDeptMap ON dbo.[EnterpriseBuffer ].PG = dbo.EnterpriseProdGroupToAnalystDeptMap.EnterprisePG)
  4. WHERE EnterpriseBuffer.PIPCode NOT IN (select buyingcode from AnalystBuffer)
However this fails due to:



now i understand why this occurs, as the sub select returns 10700 rows, the same as a select * from EnterpriseBuffer would return. i just need to update analystdepartment column for each row in EnterpriseBuffer with the EnterpriseBuffer version in EnterpriseProdGroupToAnalystDeptMap.

This sounds very coimplicating i know, but please, any information or resolution to this would be helpful.

Try the following query......

Update EnterpriseBuffer SET EnterpriseBuffer.AnalystDepartment =
(SELECT dbo.EnterpriseProdGroupToAnalystDeptMap.AnalystDep artment
FROM dbo.EnterpriseProdGroupToAnalystDeptMap
WHERE EnterprisePG = dbo.[EnterpriseBuffer].PG)

WHERE EnterpriseBuffer.PIPCode NOT IN (select buyingcode from AnalystBuffer)
Nov 23 '07 #2
Spot on!

Thanks alot, really appreciate that :D
Nov 23 '07 #3

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

Similar topics

5
by: Koen | last post by:
Hi all, I am experimenting with DAO. I wrote this sub to update one specific field of one specific row in one specific table. Nothing wrong with the SQL statement, but when I execute this I get...
8
by: RC | last post by:
In my Access 2002 form, I have a combo box and on the AfterUpdate event I use DoCmd.RunSQL ("UPDATE .... to update records in a table. When it starts to run I get a message "You are about to...
1
by: MrMike | last post by:
Hi. My application has dozens of datagrids but for some reason an exception occurs when one of them is updated. When a user edits a datagrid row and then clicks 'Update' the following exception...
3
by: Terry Olsen | last post by:
I've got 2 different web pages, both updating the same SQL database. One is for the Technician and one is for the Manager. The technician's update page works fine but the Manager's update page...
9
by: Geraldine Hobley | last post by:
Hello I'm getting the above mentioned error in my applicatio I have a datagrid bound to a datasource like s MyDatagrid.DataSource = Mydataset.Tables(Order) - this all works fine However I...
9
by: Jon | last post by:
Hi, I have a function to fill the data into the dataset: Private Sub LoadSystemDataDB(ByVal m_str As String, ByVal da As _ OleDbDataAdapter, ByVal tbName As String) Dim OleDbConn As New...
4
by: irfi | last post by:
Hi, I am a form which has a sub form, The sub form is linked with primary key of main form as a foriegn key in sub form, very basic, In the main form, I have another field which is...
3
by: Henry Stockbridge | last post by:
Hi, I need a way of bypassing the Report_Close procedure (or come up with another event to handle the Update Query.) Right now, if I set the value of Report_NoData to Cancel=True, the...
1
by: Sharon | last post by:
Hello All, Is it possible to update Sql Table through DataGrid. I have a DataGrid which is being populated through a stored procedure, all i wanted to do is to update one field...
1
by: =?Utf-8?B?UmljaA==?= | last post by:
Private Sub UpdateTblHistory() Dim strSql As String strSql = "Update tbl_History set SubscrID = @SubscrID Where ID = @ID" da.UpdateCommand.CommandText = strSql...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.