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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PortletPaulEE Topic AdvisorCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SQL

From novice to tech pro — start learning today.