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. UPDATE statement using a view

UPDATE statement using a view

Scheduled Pinned Locked Moved Database
questionannouncement
2 Posts 2 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.
  • S Offline
    S Offline
    Shrimpersfan
    wrote on last edited by
    #1

    Hi there I am trying to update a field in our contact table. I have a view which contains all of the contacts that i need to run the update for, my question is: How do i update a contact table but only update the contacts that are in my custom view?

    L 1 Reply Last reply
    0
    • S Shrimpersfan

      Hi there I am trying to update a field in our contact table. I have a view which contains all of the contacts that i need to run the update for, my question is: How do i update a contact table but only update the contacts that are in my custom view?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      This example is based on the AdventureWorks database;

      UPDATE HumanResources.Employee
      SET Title = 'updateFromView'
      WHERE EmployeeID IN (SELECT EmployeeID FROM HumanResources.vEmployee)

      The select statement gets a list of ID's in the view. You can then update all the records in the table that have this particular ID. You'll need something to identify each record individually for this to work. If there isn't, then try to add the primary key to the view. If there is no primary key defined in the base-table, add an identity to fullfill this role. Good luck :)

      I are troll :)

      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