473,804 Members | 3,526 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

UPDATE from Sub-select problem

11 New Member
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 (EnterpriseBuff er) with data from another table (EnterpriseProd GroupToAnalystD eptMap.AnalystD epartment). This is done where EnterpriseBuffe r.PG = EnterpriseProdG roupToAnalystDe ptMap.Enterpris ePG.

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 EnterpriseBuffe r would return. i just need to update analystdepartme nt column for each row in EnterpriseBuffe r with the EnterpriseBuffe r version in EnterpriseProdG roupToAnalystDe ptMap.

This sounds very coimplicating i know, but please, any information or resolution to this would be helpful.
Nov 21 '07 #1
2 1572
deepuv04
227 Recognized Expert New Member
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 (EnterpriseBuff er) with data from another table (EnterpriseProd GroupToAnalystD eptMap.AnalystD epartment). This is done where EnterpriseBuffe r.PG = EnterpriseProdG roupToAnalystDe ptMap.Enterpris ePG.

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 EnterpriseBuffe r would return. i just need to update analystdepartme nt column for each row in EnterpriseBuffe r with the EnterpriseBuffe r version in EnterpriseProdG roupToAnalystDe ptMap.

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

Try the following query......

Update EnterpriseBuffe r SET EnterpriseBuffe r.AnalystDepart ment =
(SELECT dbo.EnterpriseP rodGroupToAnaly stDeptMap.Analy stDepartment
FROM dbo.EnterpriseP rodGroupToAnaly stDeptMap
WHERE EnterprisePG = dbo.[EnterpriseBuffe r].PG)

WHERE EnterpriseBuffe r.PIPCode NOT IN (select buyingcode from AnalystBuffer)
Nov 23 '07 #2
HeavenCore
11 New Member
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
3676
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 'Invalid Operation'. ******************* code ************************* Sub UpdateObsStatusAfterStatusChange(intObsID As Integer, intNewValue As Integer)
8
11244
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 update 3 row(s)." Is there a way to prevent the message from popping up?
1
1595
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 occurs: --------------------- "Exception Details: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: index" --------------------- I've placed breakpoints with the UpdateCommand event, but...
3
1551
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 doesn't. They are both the same..as far as I can tell... --------------------- This code works fine, updating the SQL database with the edited data. Code for Tech Page
9
4296
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 have another field on the form which is a richtextbox and is bound to another field in the same datasourc like s Me.RtxtDialog.DataBindings.Add("text", MyDataset.Tables.Item("Orders"), "MyRichTextField") - this field accepts nulls in the databas
9
8426
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 OleDbConnection(OLEDB_CONNECTION_1) OleDbConn.Open() da = New OleDbDataAdapter(m_str, OleDbConn) Dim cmd As New OleDbCommandBuilder(da)
4
1702
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 investor, and in the sub form, I have created investory foreign key, this is the second link between main form and subm form.
3
2186
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 Report_Close event fires, and the message prompt is not applicable. Here is the code: Private Sub Report_Close()
1
6480
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 (FieldName-Authorised) which has a datatype bit through DataGrid but not sure how to go about it. Any Ideas Guys on this one, your help is greatly appreciated. This is the procedure used to populate the datagrid, The primary key for the table is EntryID which...
1
1633
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 da.UpdateCommand.Parameters.Add("@SubscrID", SqlDbType.VarChar, 50, "SubscrID") da.UpdateCommand.Parameters.Add("@ID", SqlDbType.Int, 4, "ID") da.Update(ds, "tbl_History")
0
9708
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9588
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10589
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10340
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10085
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9161
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7625
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5663
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4302
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.