Operand data type nvarchar(max) is invalid for subtract operator.

Help please have issue wiht stored procedure sql

SET @Query += 	 
		 '
		 SELECT				
	CASE
		WHEN
			[Group Name]= ''Infraestructura'' OR [Group Name]= ''Help desk Liv-smart'' OR  [Group Name]= ''HELP DESK''
		THEN ''ENTAEH''
		ELSE ''CBC''
		END AS ''Empresa'',
		[Group Name] AS ''Grupo'',
	COUNT([Group Name]) AS ''Añospasado'',			
		'+@Tipo_Fecha+'  AS opendate,	 
	   CASE
		WHEN
			[Group Name]= ''Infraestructura'' OR [Group Name]= ''Help desk Liv-smart'' OR  [Group Name]= ''HELP DESK''
		THEN ''ENTAEH''
		ELSE ''CBC''
		END +'-'+[Group Name] AS ''ordenPivote''		 
	FROM _SMDBA_.Incident
	WHERE country = @CN AND 
			 CONVERT(datetime,CONVERT(NVARCHAR,[Close Date & Time],101)) BETWEEN CONVERT(datetime,[Due Date & Time:],103) and CONVERT(datetime,[Close Date & Time],103) AND
	        [Due Date & Time:]  IS NOT NULL AND [Group Name] IS NOT NULL
	      GROUP BY		 
			[Group Name],			
		'+@Tipo_Fecha+',
			CASE
				WHEN
					[Group Name]= ''Infraestructura'' OR [Group Name]= ''Help desk Liv-smart'' OR  [Group Name]= ''HELP DESK''
				THEN ''ENTAEH''
				ELSE ''CBC''
				END				
			ORDER BY 
			CASE
				WHEN
					[Group Name]= ''Infraestructura'' OR [Group Name]= ''Help desk Liv-smart'' OR  [Group Name]= ''HELP DESK''
				THEN ''ENTAEH''
				ELSE ''CBC''
			'+@Tipo_Fecha+',
			END,
			 [Group Name]'
			  +@Tipo_Fecha+''

Open in new window


/
            Msg 8117, Level 16, State 1, Procedure Z_REPORTE_POR_MES, Line 108 [Batch Start Line 7]
Operand data type nvarchar(max) is invalid for subtract operator.
/
jean paul pazAsked:
Who is Participating?
 
PortletPaulfreelancerCommented:
I believe the problem is that you need 2x single quotes around the minus sign in your dynamic SQL (you only have 1x single quotes, see line 18 in question)

AS IS
            END +' - '+[Group Name] AS ''ordenPivote''            

TO BE
            END +'' - ''+[Group Name] AS ''ordenPivote''
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.