Connecting Tech Pros Worldwide Help | Site Map

Update Statments

  #1  
Old July 3rd, 2008, 04:01 PM
Member
 
Join Date: Dec 2007
Posts: 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.  
  #2  
Old July 3rd, 2008, 06:11 PM
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,168
Provided Answers: 21

re: Update Statments


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
  #3  
Old July 4th, 2008, 04:01 PM
Member
 
Join Date: Dec 2007
Posts: 46

re: Update Statments


Hi

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


Quote:
Originally Posted by ADezii
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
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
DB2 low CPU low IO (low insert,low update) why ? silverman answers 2 October 22nd, 2008 11:44 AM
update taking forever Christos Kalantzis answers 2 November 12th, 2005 10:26 AM
SELECT works but UPDATE fails. ? kalamos answers 17 July 23rd, 2005 10:27 AM
Trouble with Update syntax bolidev@hotmail.com answers 14 July 20th, 2005 04:49 AM