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. Database & SysAdmin
  3. Database
  4. error when deleting with the WITH clause?

error when deleting with the WITH clause?

Scheduled Pinned Locked Moved Database
helpquestion
5 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.
  • H Offline
    H Offline
    harcaype
    wrote on last edited by
    #1

    hi. I'm trying to delete a row by specifying the actual row number. When I call all columns from one table it does work but when I already multiselect them I get an error: Msg 4405, Level 16, State 1, Line 1 View or function 'Records ORDERED BY rowID' is not updatable because the modification affects multiple base tables. This one works:

    WITH [Records ORDERED BY rowID] AS
    (SELECT row_number() OVER (ORDER BY Records.[Plate Number] ASC) AS rowID,*)
    DELETE FROM [Records ORDERED BY rowID] WHERE rowID=1

    This one gets the error:

    WITH [Records ORDERED BY rowID] AS
    (SELECT row_number() OVER (ORDER BY Records.[Plate Number] ASC) AS rowID,
    Records.[Officer ID],
    DriverInfo.[Plate Number],
    DriverInfo.[License Number],
    DriverInfo.[Conduction Number],
    DriverInfo.[Vehicle Category],
    DriverInfo.[Vehicle Type],
    DriverInfo.[Vehicle Brand],
    DriverInfo.[Last Name],
    DriverInfo.[First Name],
    DriverInfo.[Middle Name],
    DriverInfo.[Birth Date],
    DriverInfo.[Registered Address],
    DriverInfo.[Address' City Code],
    Records.[Violation Commited],
    Violations.[Violation Code],
    Records.[Street Name],
    Records.[City of Apprehension],
    Cities.[City Code],
    Violations.[Fine Amount],
    Records.[Date/Time Apprehended]
    FROM Violations,DriverInfo,Records,Cities
    WHERE Records.[Plate Number] like DriverInfo.[Plate Number]
    and Records.[Violation Commited] like Violations.Violations
    and Records.[City of Apprehension] like Cities.City)
    DELETE FROM [Records ORDERED BY rowID] WHERE rowID=1

    T L 2 Replies Last reply
    0
    • H harcaype

      hi. I'm trying to delete a row by specifying the actual row number. When I call all columns from one table it does work but when I already multiselect them I get an error: Msg 4405, Level 16, State 1, Line 1 View or function 'Records ORDERED BY rowID' is not updatable because the modification affects multiple base tables. This one works:

      WITH [Records ORDERED BY rowID] AS
      (SELECT row_number() OVER (ORDER BY Records.[Plate Number] ASC) AS rowID,*)
      DELETE FROM [Records ORDERED BY rowID] WHERE rowID=1

      This one gets the error:

      WITH [Records ORDERED BY rowID] AS
      (SELECT row_number() OVER (ORDER BY Records.[Plate Number] ASC) AS rowID,
      Records.[Officer ID],
      DriverInfo.[Plate Number],
      DriverInfo.[License Number],
      DriverInfo.[Conduction Number],
      DriverInfo.[Vehicle Category],
      DriverInfo.[Vehicle Type],
      DriverInfo.[Vehicle Brand],
      DriverInfo.[Last Name],
      DriverInfo.[First Name],
      DriverInfo.[Middle Name],
      DriverInfo.[Birth Date],
      DriverInfo.[Registered Address],
      DriverInfo.[Address' City Code],
      Records.[Violation Commited],
      Violations.[Violation Code],
      Records.[Street Name],
      Records.[City of Apprehension],
      Cities.[City Code],
      Violations.[Fine Amount],
      Records.[Date/Time Apprehended]
      FROM Violations,DriverInfo,Records,Cities
      WHERE Records.[Plate Number] like DriverInfo.[Plate Number]
      and Records.[Violation Commited] like Violations.Violations
      and Records.[City of Apprehension] like Cities.City)
      DELETE FROM [Records ORDERED BY rowID] WHERE rowID=1

      T Offline
      T Offline
      tsaunders
      wrote on last edited by
      #2

      Because you are pulling information from multiple tables, it can not figure out which row number you are using Try changing to this for example: (SELECT Records.[Plate Number], row_number() OVER (ORDER BY Records.[Plate Number] ASC) AS rowID,

      H 1 Reply Last reply
      0
      • T tsaunders

        Because you are pulling information from multiple tables, it can not figure out which row number you are using Try changing to this for example: (SELECT Records.[Plate Number], row_number() OVER (ORDER BY Records.[Plate Number] ASC) AS rowID,

        H Offline
        H Offline
        harcaype
        wrote on last edited by
        #3

        I see. How can I use this when calling multiple tables then? I need to invoke multiple tables because I only want to delete the ones that satisfy that multiselect query. If I just use one table. The other rows that are not supposed to be included in my deletion will be deleted. Like when I want to delete row 1 in the condition of the multiselect I created, and when I only specify one table, the row 1 that it will be reading is the row 1 of that table not the multiselected table. Got any suggestions? :confused:

        1 Reply Last reply
        0
        • H harcaype

          hi. I'm trying to delete a row by specifying the actual row number. When I call all columns from one table it does work but when I already multiselect them I get an error: Msg 4405, Level 16, State 1, Line 1 View or function 'Records ORDERED BY rowID' is not updatable because the modification affects multiple base tables. This one works:

          WITH [Records ORDERED BY rowID] AS
          (SELECT row_number() OVER (ORDER BY Records.[Plate Number] ASC) AS rowID,*)
          DELETE FROM [Records ORDERED BY rowID] WHERE rowID=1

          This one gets the error:

          WITH [Records ORDERED BY rowID] AS
          (SELECT row_number() OVER (ORDER BY Records.[Plate Number] ASC) AS rowID,
          Records.[Officer ID],
          DriverInfo.[Plate Number],
          DriverInfo.[License Number],
          DriverInfo.[Conduction Number],
          DriverInfo.[Vehicle Category],
          DriverInfo.[Vehicle Type],
          DriverInfo.[Vehicle Brand],
          DriverInfo.[Last Name],
          DriverInfo.[First Name],
          DriverInfo.[Middle Name],
          DriverInfo.[Birth Date],
          DriverInfo.[Registered Address],
          DriverInfo.[Address' City Code],
          Records.[Violation Commited],
          Violations.[Violation Code],
          Records.[Street Name],
          Records.[City of Apprehension],
          Cities.[City Code],
          Violations.[Fine Amount],
          Records.[Date/Time Apprehended]
          FROM Violations,DriverInfo,Records,Cities
          WHERE Records.[Plate Number] like DriverInfo.[Plate Number]
          and Records.[Violation Commited] like Violations.Violations
          and Records.[City of Apprehension] like Cities.City)
          DELETE FROM [Records ORDERED BY rowID] WHERE rowID=1

          L Offline
          L Offline
          leoinfo
          wrote on last edited by
          #4

          Is it this what you are looking for?

          WITH ORDERED_RECORDS AS(
          SELECT
          row_number() OVER (ORDER BY Records.[Plate Number] ASC) AS rowID
          ,Records.[Officer ID]
          ,DriverInfo.[Plate Number]
          ,DriverInfo.[License Number]
          ,DriverInfo.[Conduction Number]
          ,DriverInfo.[Vehicle Category]
          ,DriverInfo.[Vehicle Type]
          ,DriverInfo.[Vehicle Brand]
          ,DriverInfo.[Last Name]
          ,DriverInfo.[First Name]
          ,DriverInfo.[Middle Name]
          ,DriverInfo.[Birth Date]
          ,DriverInfo.[Registered Address]
          ,DriverInfo.[Address' City Code]
          ,Records.[Violation Commited]
          ,Violations.[Violation Code]
          ,Records.[Street Name]
          ,Records.[City of Apprehension]
          ,Cities.[City Code]
          ,Violations.[Fine Amount]
          ,Records.[Date/Time Apprehended]
          FROM Violations
          ,DriverInfo
          ,Records
          ,Cities
          WHERE Records.[Plate Number] like DriverInfo.[Plate Number]
          and Records.[Violation Commited] like Violations.Violations
          and Records.[City of Apprehension] like Cities.City
          )
          DELETE FROM Records
          WHERE Records.[Plate Number]
          IN (
          SELECT [Plate Number]
          FROM ORDERED_RECORDS
          WHERE rowID=1
          )

          H 1 Reply Last reply
          0
          • L leoinfo

            Is it this what you are looking for?

            WITH ORDERED_RECORDS AS(
            SELECT
            row_number() OVER (ORDER BY Records.[Plate Number] ASC) AS rowID
            ,Records.[Officer ID]
            ,DriverInfo.[Plate Number]
            ,DriverInfo.[License Number]
            ,DriverInfo.[Conduction Number]
            ,DriverInfo.[Vehicle Category]
            ,DriverInfo.[Vehicle Type]
            ,DriverInfo.[Vehicle Brand]
            ,DriverInfo.[Last Name]
            ,DriverInfo.[First Name]
            ,DriverInfo.[Middle Name]
            ,DriverInfo.[Birth Date]
            ,DriverInfo.[Registered Address]
            ,DriverInfo.[Address' City Code]
            ,Records.[Violation Commited]
            ,Violations.[Violation Code]
            ,Records.[Street Name]
            ,Records.[City of Apprehension]
            ,Cities.[City Code]
            ,Violations.[Fine Amount]
            ,Records.[Date/Time Apprehended]
            FROM Violations
            ,DriverInfo
            ,Records
            ,Cities
            WHERE Records.[Plate Number] like DriverInfo.[Plate Number]
            and Records.[Violation Commited] like Violations.Violations
            and Records.[City of Apprehension] like Cities.City
            )
            DELETE FROM Records
            WHERE Records.[Plate Number]
            IN (
            SELECT [Plate Number]
            FROM ORDERED_RECORDS
            WHERE rowID=1
            )

            H Offline
            H Offline
            harcaype
            wrote on last edited by
            #5

            Oh gosh. Thanks! I GOT IT WORKING FINALLY!!!! THANK YOU SOOO SOOO MUCH!!!!!! :-D

            modified on Thursday, July 17, 2008 12:38 PM

            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