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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. SQL update query

SQL update query

Scheduled Pinned Locked Moved Database
databaseannouncement
10 Posts 5 Posters 1 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
    Mattzimmerer
    wrote on last edited by
    #1

    This one should be easy :omg: ... I cant get a simple parametrized update query to function at all... This is a simplified version of what I am trying to do...

    UPDATE TheDatabase

    SET ([Vehicle #] = @NewVehNo)

    WHERE ([Vehicle #] = @OldVehNO)

    I dont enderstand why this is wrong... I suck at SQL lol... from MSDN i get the format:

    UPDATE ShoppingCart
    SET (BookId = @bookid, CustId = @custid, Quantity = @quantity)
    WHERE (BookId = @bookid AND CustId = @custid)

    L D M 3 Replies Last reply
    0
    • M Mattzimmerer

      This one should be easy :omg: ... I cant get a simple parametrized update query to function at all... This is a simplified version of what I am trying to do...

      UPDATE TheDatabase

      SET ([Vehicle #] = @NewVehNo)

      WHERE ([Vehicle #] = @OldVehNO)

      I dont enderstand why this is wrong... I suck at SQL lol... from MSDN i get the format:

      UPDATE ShoppingCart
      SET (BookId = @bookid, CustId = @custid, Quantity = @quantity)
      WHERE (BookId = @bookid AND CustId = @custid)

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      UPDATE targets a table, not a database. suggestion: stop using those field names full of special characters, and get rid of those square brackets then. :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


      I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.


      1 Reply Last reply
      0
      • M Mattzimmerer

        This one should be easy :omg: ... I cant get a simple parametrized update query to function at all... This is a simplified version of what I am trying to do...

        UPDATE TheDatabase

        SET ([Vehicle #] = @NewVehNo)

        WHERE ([Vehicle #] = @OldVehNO)

        I dont enderstand why this is wrong... I suck at SQL lol... from MSDN i get the format:

        UPDATE ShoppingCart
        SET (BookId = @bookid, CustId = @custid, Quantity = @quantity)
        WHERE (BookId = @bookid AND CustId = @custid)

        D Offline
        D Offline
        Don Burton
        wrote on last edited by
        #3

        Get rid of the parens. Such as: UPDATE Thetable SET [Vehicle #] = @NewVehNo WHERE [Vehicle #] = @OldVehNO and I assume you are updating a table - Yes?

        M 1 Reply Last reply
        0
        • D Don Burton

          Get rid of the parens. Such as: UPDATE Thetable SET [Vehicle #] = @NewVehNo WHERE [Vehicle #] = @OldVehNO and I assume you are updating a table - Yes?

          M Offline
          M Offline
          Mattzimmerer
          wrote on last edited by
          #4

          wait yes... i replaced that for some reason... i am updating a table

          UPDATE [dbo].[Pickups & Cars]

          SET ([Vehicle #] = @Vehicle_NO)

          WHERE ([Vehicle #] = @Vehicle_NO)

          this doesnt work...

          D I 2 Replies Last reply
          0
          • M Mattzimmerer

            wait yes... i replaced that for some reason... i am updating a table

            UPDATE [dbo].[Pickups & Cars]

            SET ([Vehicle #] = @Vehicle_NO)

            WHERE ([Vehicle #] = @Vehicle_NO)

            this doesnt work...

            D Offline
            D Offline
            Don Burton
            wrote on last edited by
            #5

            Get rid of the parens: UPDATE [dbo].[Pickups & Cars] SET [Vehicle #] = @Vehicle_NO WHERE [Vehicle #] = @Vehicle_NO Have tried the SP in Query Analyzer?

            M 1 Reply Last reply
            0
            • D Don Burton

              Get rid of the parens: UPDATE [dbo].[Pickups & Cars] SET [Vehicle #] = @Vehicle_NO WHERE [Vehicle #] = @Vehicle_NO Have tried the SP in Query Analyzer?

              M Offline
              M Offline
              Mattzimmerer
              wrote on last edited by
              #6

              I guess the parens were messing it up... thanks!

              1 Reply Last reply
              0
              • M Mattzimmerer

                wait yes... i replaced that for some reason... i am updating a table

                UPDATE [dbo].[Pickups & Cars]

                SET ([Vehicle #] = @Vehicle_NO)

                WHERE ([Vehicle #] = @Vehicle_NO)

                this doesnt work...

                I Offline
                I Offline
                i j russell
                wrote on last edited by
                #7

                Are you getting an error when you run the update? Have you tried running the update against a vehicle that you know exists in the database rather than a variable? eg UPDATE .... WHERE [Vehicle #] = 1;

                1 Reply Last reply
                0
                • M Mattzimmerer

                  This one should be easy :omg: ... I cant get a simple parametrized update query to function at all... This is a simplified version of what I am trying to do...

                  UPDATE TheDatabase

                  SET ([Vehicle #] = @NewVehNo)

                  WHERE ([Vehicle #] = @OldVehNO)

                  I dont enderstand why this is wrong... I suck at SQL lol... from MSDN i get the format:

                  UPDATE ShoppingCart
                  SET (BookId = @bookid, CustId = @custid, Quantity = @quantity)
                  WHERE (BookId = @bookid AND CustId = @custid)

                  M Offline
                  M Offline
                  Mycroft Holmes
                  wrote on last edited by
                  #8

                  I would emphasize what Luc said, you need to go through your entire database and remove the spaces and special characters from the table and field names NOW. If you do not do this now it will drive you nuts and may cause compatibility problems in the future. Some tools will not accept [Vehicle #].

                  Never underestimate the power of human stupidity RAH

                  M 1 Reply Last reply
                  0
                  • M Mycroft Holmes

                    I would emphasize what Luc said, you need to go through your entire database and remove the spaces and special characters from the table and field names NOW. If you do not do this now it will drive you nuts and may cause compatibility problems in the future. Some tools will not accept [Vehicle #].

                    Never underestimate the power of human stupidity RAH

                    M Offline
                    M Offline
                    Mattzimmerer
                    wrote on last edited by
                    #9

                    Ok, Ill restrict my database to letters only... underscores shouldnt cause problems right?

                    M 1 Reply Last reply
                    0
                    • M Mattzimmerer

                      Ok, Ill restrict my database to letters only... underscores shouldnt cause problems right?

                      M Offline
                      M Offline
                      Mycroft Holmes
                      wrote on last edited by
                      #10

                      No underscores are fine they will just irritate you, most developers try and avoid them. Take a look through most sample code in the articles and things like northwind, very few underscores.

                      Never underestimate the power of human stupidity RAH

                      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