Skip to content
Advertisement

SQL – Datatypes varchar and varchar are incompatible in the modulo operator [closed]

enter image description hereI have the following query that used to work but returns the error addressed on the title. The last line is indicated within the error.

UPDATE [dwh].[dbo].[opco_securty]
SET opco_general = REPLACE([dwh].[dbo].[opco_securty].opco_general, [MSTR_MD].[dbo].[v_OpcoGeneral_UserList].ABBREVIATION, '''')
FROM [dwh].[dbo].[opco_securty]
JOIN [MSTR_MD].[dbo].[v_OpcoGeneral_UserList]
ON [dbo].[opco_securty].opco_general LIKE CONCAT(''%'', [MSTR_MD].[dbo].[v_OpcoGeneral_UserList].ABBREVIATION, ''%'');

Advertisement

Answer

Change this

ON [dbo].[opco_securty].opco_general LIKE CONCAT(''%'', [MSTR_MD].[dbo].[v_OpcoGeneral_UserList].ABBREVIATION, ''%'');

To this

ON [dbo].[opco_securty].opco_general LIKE CONCAT('%', [MSTR_MD].[dbo].[v_OpcoGeneral_UserList].ABBREVIATION, '%');

Because the goal is to concatinate the % character to the column. So that it creates a string that’s usable by the LIKE.

But in MS Sql Server you escape a single quote with a single quote.

So the ''%'' is messing things up.
Because the % is seen as the modulus operator.

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