Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2004
    Posts
    3

    Wink Unanswered: Simple SQL Update

    Hello all and I look forward to reading your replys. Currently, I'm trying to update a table in my SQL database by writing a script that will go get the field name and correct info, verify it has the correct field by using two other columns and then update the information.

    I do not know how to use tell SQL what to update when the field name can change. I've used the following in the past.

    UPDATE [Import Table]

    SET [Import Table].[???] = [Correction_Table].[Correct_Info]

    WHERE [Import Table].[UNIQUE ID] in (select [USO Unique ID] from [Correction_Table])

    IN this new instance, I'm reading the Field_Name from the Correction_Table so I don't know what to put in my SET statement.

    Please any help or pointers in the right direction would be greatly appreciated.

    Battle_n

  2. #2
    Join Date
    Oct 2002
    Posts
    66
    Would this work?

    UPDATE ImportTable

    SET ImportTable.MyField = (select Correction_Table.Correct_Info from Correction_Table WHERE Correction_Table.USO_Unique_ID = ImportTable.UNIQUE_ID)

  3. #3
    Join Date
    Mar 2004
    Posts
    3
    This wouldn't work because "MyField" keeps changing depending on the field to be corrected. I'm going to have to put that as a variable and read in the value to the string.

    Thanks

  4. #4
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1
    You need to use dynamic SQL. But what DBMS are you using?

  5. #5
    Join Date
    Mar 2004
    Posts
    3
    SQL Server Enterprise Manager. I want to overright incorrect data from a feed.

Posting Permissions

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