Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. sql update sum

sql update sum

Scheduled Pinned Locked Moved Visual Basic
databasecsharpquestionannouncement
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    maytel mynt
    wrote on last edited by
    #1

    is this possible in visual basic.net? cant seem to make it work vb.net using access database oledb update t1 set t1.f1 = (select sum(t2.f1) from t2 where t1.code=t2.code) ty in adv

    C A 2 Replies Last reply
    0
    • M maytel mynt

      is this possible in visual basic.net? cant seem to make it work vb.net using access database oledb update t1 set t1.f1 = (select sum(t2.f1) from t2 where t1.code=t2.code) ty in adv

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      You're posting SQL. Does the SQL work in Access ? If not, that is your issue. if so, then your issue is with the code you're not posting, the code that is appropriate for this forum. You know, in VB.

      Christian Graus No longer a Microsoft MVP, but still happy to answer your questions.

      1 Reply Last reply
      0
      • M maytel mynt

        is this possible in visual basic.net? cant seem to make it work vb.net using access database oledb update t1 set t1.f1 = (select sum(t2.f1) from t2 where t1.code=t2.code) ty in adv

        A Offline
        A Offline
        astanton1978
        wrote on last edited by
        #3

        In MSSQL, the syntax would be UPDATE t1 SET f1 = SUM(t2.f1) FROM t1 INNER JOIN t2 ON t1.code = t2.code I assume it would be the same in Access. The key here is that the column receiving the update is not aliased, and any tables used in the update need to have their own references in the FROM statement. Don't use old style SQL Join syntax (from t1, t2 where t1.code=t2.code) if you can help it. Its difficult to follow.

        M 1 Reply Last reply
        0
        • A astanton1978

          In MSSQL, the syntax would be UPDATE t1 SET f1 = SUM(t2.f1) FROM t1 INNER JOIN t2 ON t1.code = t2.code I assume it would be the same in Access. The key here is that the column receiving the update is not aliased, and any tables used in the update need to have their own references in the FROM statement. Don't use old style SQL Join syntax (from t1, t2 where t1.code=t2.code) if you can help it. Its difficult to follow.

          M Offline
          M Offline
          maytel mynt
          wrote on last edited by
          #4

          ty for the reply but i get this error Syntax error (missing operator) in query expression 'SUM(Accessory_Table.Qty * Accessory_Table.Cost) FROM Stock_Table INNER JOIN Accessory_Table ON Stock_Table.StkCode = Accessory_Table.StkCode'. this is my actual code "UPDATE Stock_Table " & _ "SET StkCost = SUM(Accessory_Table.Qty * Accessory_Table.Cost) " & _ "FROM Stock_Table " & _ "INNER JOIN Accessory_Table " & _ "ON Stock_Table.StkCode = Accessory_Table.StkCode" maybe UPDATE and SUM doesnt really work together in access?

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups