Skip to content
Advertisement

INSERT ‘X’ If another column is updated

I need to update column firstname in table Taulu ( removing single quotes ). I also need to add ‘X’ to another column sq if values where updated.
I would like to update this in one statement.

What I tried so far:

UPDATE Taulu set 
firstname = REPLACE(dataa, '''', ''), 
IF SELECT firstname from Taulu 
WHERE 
firstname LIKE '%''%' OR 
firstname LIKE '''%' OR 
firstname LIKE '%''' <> '' sq= 'X' 
ELSE sq= '')

Advertisement

Answer

Something like this, I think:

UPDATE Taulu 
    SET firstname = REPLACE(dataa, '''', ''), 
        sq = 'X'
    WHERE firstname LIKE '%''%' ;

The WHERE clause should identify only the rows that will be updated (those with single quotes). I’m not sure if the assignment to sq should be a simple assignment or sq = sq + 'X'.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement