Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2009
    Posts
    2

    Question Unanswered: Updating Column in a Table

    Hi,

    I am new to SQL Server and SQL programming. I am using SQL Server 2005. I have a table defined as below:
    CREATE TABLE data1
    (
    --_id bigint IDENTITY,
    _ResourceGuid uniqueidentifier,
    DeviceAssetTag nvarchar(512),
    DeviceServiceTag nvarchar(512),
    DeviceSystemId nvarchar(512),
    DeviceLocation nvarchar(512),
    DeviceName nvarchar(512),
    DeviceChassisServiceTag nvarchar(512),
    DeviceSystemModelType nvarchar(512),
    DeviceManufacturer nvarchar(512),
    DeviceDescription nvarchar(512),
    DeviceSerialNumber nvarchar(512),
    DeviceVirtualIP nvarchar(512)
    )
    This table has 2000 rows. The column DeviceServiceTag currently has invalid values in the table and I have to update all the values for it in the table. The correct values are there in a CSV file. I want to update the column DeviceServiceTag with the values in the file.
    May somebody please help me in with the SQL.?
    Thanks in Advance !!

    -Ashish

  2. #2
    Join Date
    Nov 2004
    Posts
    1,427
    Provided Answers: 4
    I presume the CSV-file has at least the columns _ResourceGuid and DeviceServiceTag.

    - Create a temporary table TEMPTABLE that can hold all the columns from the CSV file.
    - Insert the CSV data into TEMPTABLE.
    - Then do the UPDATE of the table data1:
    Code:
    UPDATE data1
    SET DeviceServiceTag = TEMPTABLE.DeviceServiceTag 
    FROM TEMPTABLE
    WHERE  data1._ResourceGuid = TEMPTABLE._ResourceGuid
    - DROP the TEMPTABLE.
    With kind regards . . . . . SQL Server 2000/2005/2012
    Wim

    Grabel's Law: 2 is not equal to 3 -- not even for very large values of 2.
    Pat Phelan's Law: 2 very definitely CAN equal 3 -- in at least two programming languages

  3. #3
    Join Date
    Aug 2009
    Posts
    2

    Smile

    Thanks Wim !! This works !!

Posting Permissions

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