Updating Multiple Columns Using Microsoft SQL Server

advertisements

I am trying to write an SQL script where I can replace data in multiple columns, see below:

SQL Script:

UPDATE SohailsTest.dbo.OBJECT
SET VARIABLE = REPLACE(VARIABLE, 'C:\', 'E:\')
SET STATIC = REPLACE(STATIC, 'C:\', 'E:\');

I have tried the above, but it says:

Error Message:

Msg 102, Level 15, State 1, Line 3 Incorrect syntax near '='.

What am I doing wrong?


You need to use only one SET:

UPDATE SohailsTest.dbo.OBJECT
SET [VARIABLE] = REPLACE([VARIABLE], 'C:\', 'E:\'),
    [STATIC] = REPLACE([STATIC], 'C:\', 'E:\');