You get this error due to an implicit conversion. One part of CASE returns NVARCHAR(50) ie CONVERT(NVARCHAR(50), dbo.Activitat.DataManual) , which cannot be converted to int , and the other returns int ie DATEPART(DAY,Activitat.Datafi) .
Something like this will also return the same error.
SELECT CASE WHEN 1=2 THEN 1 ELSE 'errorstring' END
You must CONVERT and return NVARCHAR(50) in both cases so that there is no implicit conversion. Something like that.
CASE WHEN dbo.Activitat.DataInici is null THEN CONVERT(NVARCHAR(50),DATEPART(DAY,Activitat.Datafi)) ELSE CONVERT(NVARCHAR(50), dbo.Activitat.DataManual) END
ughai source share