473,395 Members | 1,790 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,395 software developers and data experts.

Update Statments

46
Hi All
Please help me .Hope i have described my problem clearly below.
I have a condition where i need to update some data in table from the value taken from another table.So basically i need to create a update statment to perform the data manipulation.but i am not able to write the update statments.I have two tables..Tab_Bookings and tab_Booking_Fare_Lines .Both are joined by field Booking_ID.Now there is a column No_Passengers in Tab_Booking and there is a column called Number_of_Passengers in Tab_Booking_child.Now i want a update statment which will update No_of_Pass_Type_1 column in Tab_Booking table from
tab_Booking_Fare_Lines for each booking_ID.Thanks in advance.The main problem for me here is that data is in one to many data.so i need to take the Sum([tab_Booking_Fare_Lines].[Number_of_Passengers])
I have written a update statements but its creating an error for me which says "You tried to execute a query that doesnot inclue expression No_of_Pass_Type_1 as part of aggregate function.

Thanks in advance

Expand|Select|Wrap|Line Numbers
  1.  
  2. UPDATE tab_Bookings INNER JOIN tab_Booking_Fare_Lines ON tab_Bookings.File_No = tab_Booking_Fare_Lines.Booking_Id SET tab_Bookings.No_of_Pass_Type_1 = Sum([tab_Booking_Fare_Lines].[Number_of_Passengers])
  3.  
  4.  
Jul 3 '08 #1
2 1494
ADezii
8,834 Expert 8TB
Your description of the problem is a little confusing and contradictory, but it can be solved in the following manner. I'm sure there is a SQL answer, but right now it elludes me.
Expand|Select|Wrap|Line Numbers
  1. Dim MyDB As DAO.Database
  2. Dim MyRS As DAO.Recordset
  3. Dim lngTotalPassengers As Long
  4.  
  5. Set MyDB = CurrentDb()
  6. Set MyRS = MyDB.OpenRecordset("Tab_Bookings", dbOpenDynaset)
  7.  
  8. Do While Not MyRS.EOF
  9.   lngTotalPassengers = Nz(DSum("Number_Of_Passengers", "Tab_Booking_Fare_Lines", _
  10.                                "[Booking_ID] = " & MyRS![Booking_ID]), 0)
  11.     MyRS.Edit
  12.       MyRS![No_Passengers] = lngTotalPassengers
  13.     MyRS.Update
  14.   MyRS.MoveNext
  15. Loop
  16.  
  17. MyRS.Close
  18. Set MyRS = Nothing
Jul 3 '08 #2
ramdil
46
Hi

Thanks for VBA code.If you find sql query and if you have time then do please post it.


Your description of the problem is a little confusing and contradictory, but it can be solved in the following manner. I'm sure there is a SQL answer, but right now it elludes me.
Expand|Select|Wrap|Line Numbers
  1. Dim MyDB As DAO.Database
  2. Dim MyRS As DAO.Recordset
  3. Dim lngTotalPassengers As Long
  4.  
  5. Set MyDB = CurrentDb()
  6. Set MyRS = MyDB.OpenRecordset("Tab_Bookings", dbOpenDynaset)
  7.  
  8. Do While Not MyRS.EOF
  9.   lngTotalPassengers = Nz(DSum("Number_Of_Passengers", "Tab_Booking_Fare_Lines", _
  10.                                "[Booking_ID] = " & MyRS![Booking_ID]), 0)
  11.     MyRS.Edit
  12.       MyRS![No_Passengers] = lngTotalPassengers
  13.     MyRS.Update
  14.   MyRS.MoveNext
  15. Loop
  16.  
  17. MyRS.Close
  18. Set MyRS = Nothing
Jul 4 '08 #3

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

Similar topics

14
by: bolidev | last post by:
I'm new to SQL and can't figure out how to update my table (StoreItemStatus) that contains the current status for items in each store (STORE_KEY, ITEM_KEY, STATUS,...). I get updated status info...
5
by: Angelina | last post by:
Hi, I need some help in writing a 'if-then-else' statement. I currently have wrote one that looks something like this.. If Combobox1 = xxx and textbox1 <> "" then 'run stored procedure 1 to...
4
by: Jesper | last post by:
Hi, I would like to issue three statements to the database (mysql v4.1) each time the server starts up. Is there any built in way to do this? Like a init file to put them in? At the moment I...
17
by: kalamos | last post by:
This statement fails update ded_temp a set a.balance = (select sum(b.ln_amt) from ded_temp b where a.cust_no = b.cust_no and a.ded_type_cd = b.ded_type_cd and a.chk_no = b.chk_no group by...
2
by: Christos Kalantzis | last post by:
Hello Gentlemen, I have a table which is the highest level table in my DB design...ie...all tables have foreign keys that if the chain is followed, lead to this table. This table had quite a...
3
by: Vinny Vinn | last post by:
I have used simple batch statments with C#.for example: string select = "select model from cars where id = ?;select * from trucks where model = ?"; where ? is a parameter whose value i have...
8
by: buc | last post by:
I have a simple combox on the screen that is bound via a datareader to a stored proc in sql that returns a simple string. The code is 'load stored proc then dReader =...
10
by: WazzaRoberts | last post by:
Hi, i have a simply problem but for the life of me cannot find a solution. all i wnat to do is change the tiltle (textbox) on a report when it opens. I open the report with the following code ...
2
by: silverman | last post by:
Hi, Im facing a very strange problem with DB2. when my app reach a certain number of concurrence (not much about 50) the performance of all DB2 systems decreases for Insert and Update statments. I...
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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.