Skip to content
Advertisement

Why am I getting an error when using the REPLACE function with a WHERE clause?

I am using SQL Server and SSMS.

I have the following code:

But I get the following error:

Msg 174, Level 15, State 1, Line 2
The replace function requires 3 argument(s).

I’d like to change G1 to G2 and C11 to C33. This is a small sample of a much larger code I’d like to build replacing many other similar codes.

Advertisement

Answer

You can use CASE for your “if” logic in SQL, so like this:

You can use more conditions too:

At this point it is starting to look like a lookup table would be nice though.

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