Below is my Query in which im trying to combine multiple column values
SELECT DISTINCT CONVERT(varchar, Em.ADDR1) - CONVERT(varchar, Em.ADDR2) - CONVERT(varchar, Em.ADDR3) - CONVERT(varchar, Dm.DIST_NAME) - CONVERT(varchar,Sm.STATE_NAME)
- CONVERT(varchar, Cm.COUNTRY_NAME) AS Expr1
FROM EMP_MST AS Em INNER JOIN
DESIG_MST AS Dsgm ON Em.DESIG_NO = Dsgm.DESIG_NO AND Dsgm.COMPANY_NO = Em.COMPANY_NO INNER JOIN
DEPT_MST AS Dptm ON Em.DEPT_NO = Dptm.DEPT_NO AND Dptm.COMPANY_NO = Em.COMPANY_NO INNER JOIN
COUNTRY_MST AS Cm ON Em.COUNTRY_NO = Cm.COUNTRY_NO INNER JOIN
STATE_MST AS Sm ON Em.STATE_NO = Sm.STATE_NO AND Em.COUNTRY_NO = Sm.COUNTRY_NO INNER JOIN
DIST_MST AS Dm ON Em.DIST_NO = Dm.DIST_NO AND Em.STATE_NO = Dm.STATE_NO AND Em.COUNTRY_NO = Dm.COUNTRY_NO LEFT OUTER JOIN
EMP_MST AS MEm ON Em.MANAGER = MEm.EMP_NO
WHERE (1 = 1) AND (Em.EMP_NO LIKE '%%') AND (Em.COMPANY_NO = 1)
When I’m executing the Query , I’m getting
Error:
operand data type varchar is invalid for subtract operator in sqlServer
As people have said it’s a bit hard to follow the exact query, but the specific issue, as the error states, is that you’re using a
-operator onvarcharcolumns.If you’re trying to concatenate
varcharvalues you should be using the+operator, something like:If these columns are all
varcharalready you probably don’t need theCONVERTfunctions, either.