Update the specific column value in table

  • Hi,

    I have an existing table TableA which has multiple columns. Now one of the column name is ServerType which has a value "Test". Now I have to replace the value 'Test' which is in the ServerType Column to "Dev". so how do I do it with Tsql.  Will the below query work and only update the specific field and not all..The scenario is if the value in company column is say blue then replace/update the value to dev from test. or we can also check only for 'test' since it is unique value in that column and just replace it.

    Example below

    Sample Query

    Use Test

    UPDATE TableA

    SET ServerType = 'Dev'

    Where ServerType ='Test'

    Sample table structure

    USE TEST

    GO

    CREATE TABLE [dbo].[TABLEA](

    [Form] [nvarchar](100) NULL,

    [Company] [nvarchar](100) NULL,

    [ServerType] [nvarchar](100) NULL

    ) ON [PRIMARY]

    GO

  • Your code will replace "Test" with "Dev" in the ServerType column for the entire table.

    If you wish to only do the update where Company is "Blue", then you need to change as follows

    UPDATE TableA
    SET ServerType = 'Dev'
    WHERE ServerType ='Test'
    AND Comapny = 'Blue'

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply