+ Post New Thread
Results 1 to 4 of 4
Coding Thread, SQL UPDATE using a view in Coding and Web Development; Hi there I am trying to update a field in our contact table. I have a view which contains all ...
  1. #1
    Shrimpersfan's Avatar
    Join Date
    Feb 2008
    Location
    Peterborough
    Posts
    52
    Thank Post
    9
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    SQL UPDATE using a view

    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?

  2. #2

    powdarrmonkey's Avatar
    Join Date
    Feb 2008
    Location
    Alcester, Warwickshire
    Posts
    4,855
    Thank Post
    412
    Thanked 777 Times in 650 Posts
    Rep Power
    181
    You need a JOIN clause.

  3. #3

    Join Date
    May 2008
    Location
    Cheshire
    Posts
    270
    Thank Post
    47
    Thanked 27 Times in 24 Posts
    Rep Power
    18
    Hi there, you might want to look at something like:

    Code:
    Update TableName Set FieldName = CustomView.Field 
    From TableName
    Inner Join CustomView on
    TableName.PrimaryKeyField = CustomView.ForeignKeyField

  4. #4
    pauljonze's Avatar
    Join Date
    May 2008
    Location
    Staffs
    Posts
    86
    Thank Post
    17
    Thanked 22 Times in 15 Posts
    Rep Power
    21
    If all columns are the same I'd use something like:

    select *
    from (select * from old_data_table_name)
    union
    select * from new_data_view_name)
    into temp_data_table

    drop old_data_table

    select *
    into old_data_table_name
    from temp_data_table

    drop temp_data_table

    Bit rough and ready because you're creating a new table of contacts and need to drop the old contact table but it works...

SHARE:
+ Post New Thread

Similar Threads

  1. SQL update query
    By MACIT in forum Coding
    Replies: 4
    Last Post: 27th October 2008, 08:20 PM
  2. MS SQL 2005 - Dump SQL
    By tom_newton in forum Windows
    Replies: 7
    Last Post: 23rd January 2008, 05:10 PM
  3. Microsoft Debuts Update Update Suite
    By mattx in forum General Chat
    Replies: 4
    Last Post: 1st November 2007, 04:07 PM
  4. August update + SQL change compulsary?
    By zag in forum MIS Systems
    Replies: 8
    Last Post: 8th October 2007, 08:11 AM
  5. August Update Without SQL
    By enjay in forum MIS Systems
    Replies: 10
    Last Post: 31st August 2007, 12:58 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •