我有以下代码
SELECT dbo.COL_V_Cost_GEMS_Detail.TNG_SYS_NR AS [EHP Code],
dbo.COL_TBL_VCOURSE_NEW.TNG_NA AS [Course Title],
dbo.COL_TBL_VCOURSE_NEW.FCT_TYP_CD & dbo.COL_TBL_VCOURSE_NEW.DEP_TYP_CD AS [Course Owner],
dbo.COL_TBL_VCOURSE_TYP.TNG_DESC AS [TYPE OF TRAINING],
dbo.COL_V_Cost_GEMS_Detail.JOB_FCT_CD,
dbo.COL_V_Cost_GEMS_Detail.JOB_GRP_CD,
dbo.COL_V_Cost_GEMS_Detail.ST_COST_SUM + dbo.COL_V_Cost_GEMS_Detail.IN_COST_SUM AS [Total Cost],
SUM(dbo.COL_V_Cost_GEMS_Detail.STUDENTS) AS SumOfSTUDENTS,
SUM(dbo.COL_V_Cost_GEMS_Detail.INSTRUCTORS) AS SumOfINSTRUCTORS,
SUM(dbo.COL_V_Cost_GEMS_Detail.ST_HOURS_SUM) AS ST_HOURS,
SUM(dbo.COL_V_Cost_GEMS_Detail.ST_COST_SUM) AS ST_COST,
SUM(dbo.COL_V_Cost_GEMS_Detail.IN_HOURS_SUM) AS IN_HOURS,
SUM(dbo.COL_V_Cost_GEMS_Detail.IN_COST_SUM) AS IN_COST
FROM dbo.COL_V_Cost_GEMS_Detail INNER JOIN dbo.COL_TBL_VCOURSE_NEW
ON dbo.COL_V_Cost_GEMS_Detail.TNG_SYS_NR = dbo.COL_TBL_VCOURSE_NEW.TNG_SYS_NR
INNER JOIN dbo.COL_TBL_VCOURSE_TYP
ON dbo.COL_TBL_VCOURSE_NEW.TNG_MDA_TYP_CD = dbo.COL_TBL_VCOURSE_TYP.TNG_TYP
WHERE (dbo.COL_V_Cost_GEMS_Detail.RRDD NOT LIKE '%12%')
AND
(dbo.COL_V_Cost_GEMS_Detail.RRDD NOT LIKE '%13%')
AND
(dbo.COL_V_Cost_GEMS_Detail.RRDD NOT LIKE '%2706%')
AND
(dbo.COL_V_Cost_GEMS_Detail.RRDD NOT LIKE '%2707%')
AND
(dbo.COL_V_Cost_GEMS_Detail.RRDD NOT LIKE '%2331%')
GROUP BY dbo.COL_V_Cost_GEMS_Detail.TNG_SYS_NR,
dbo.COL_TBL_VCOURSE_NEW.TNG_NA,
dbo.COL_TBL_VCOURSE_NEW.FCT_TYP_CD & dbo.COL_TBL_VCOURSE_NEW.DEP_TYP_CD,
dbo.COL_TBL_VCOURSE_TYP.TNG_DESC,
dbo.COL_V_Cost_GEMS_Detail.JOB_FCT_CD,
dbo.COL_V_Cost_GEMS_Detail.JOB_GRP_CD,
dbo.COL_V_Cost_GEMS_Detail.ST_COST_SUM +
dbo.COL_V_Cost_GEMS_Detail.IN_COST_SUM
我一直收到错误
Msg 402, Level 16, State 1, Line 1
The data types nvarchar and nvarchar are incompatible in the boolean AND operator.
无论我做出什么改变,我似乎都无法摆脱这个错误。起初我以为它会是数据类型,但它们都很好,我认为它是一些符号,但替换它们也不起作用。
答案 0 :(得分:1)
好像你有一个&试着改变它!
答案 1 :(得分:1)
我删除了&amp ;.如果这是否有效,请尝试此操作。
SELECT dbo.COL_V_Cost_GEMS_Detail.TNG_SYS_NR AS [EHP Code], dbo.COL_TBL_VCOURSE_NEW.TNG_NA AS [Course Title],
dbo.COL_TBL_VCOURSE_NEW.FCT_TYP_CD, dbo.COL_TBL_VCOURSE_NEW.DEP_TYP_CD AS [Course Owner],
dbo.COL_TBL_VCOURSE_TYP.TNG_DESC AS [TYPE OF TRAINING], dbo.COL_V_Cost_GEMS_Detail.JOB_FCT_CD, dbo.COL_V_Cost_GEMS_Detail.JOB_GRP_CD,
dbo.COL_V_Cost_GEMS_Detail.ST_COST_SUM + dbo.COL_V_Cost_GEMS_Detail.IN_COST_SUM AS [Total Cost], SUM(dbo.COL_V_Cost_GEMS_Detail.STUDENTS)
AS SumOfSTUDENTS, SUM(dbo.COL_V_Cost_GEMS_Detail.INSTRUCTORS) AS SumOfINSTRUCTORS, SUM(dbo.COL_V_Cost_GEMS_Detail.ST_HOURS_SUM)
AS ST_HOURS, SUM(dbo.COL_V_Cost_GEMS_Detail.ST_COST_SUM) AS ST_COST, SUM(dbo.COL_V_Cost_GEMS_Detail.IN_HOURS_SUM) AS IN_HOURS,
SUM(dbo.COL_V_Cost_GEMS_Detail.IN_COST_SUM) AS IN_COST
FROM dbo.COL_V_Cost_GEMS_Detail INNER JOIN
dbo.COL_TBL_VCOURSE_NEW ON dbo.COL_V_Cost_GEMS_Detail.TNG_SYS_NR = dbo.COL_TBL_VCOURSE_NEW.TNG_SYS_NR INNER JOIN
dbo.COL_TBL_VCOURSE_TYP ON dbo.COL_TBL_VCOURSE_NEW.TNG_MDA_TYP_CD = dbo.COL_TBL_VCOURSE_TYP.TNG_TYP
WHERE (dbo.COL_V_Cost_GEMS_Detail.RRDD NOT LIKE '%12%') AND (dbo.COL_V_Cost_GEMS_Detail.RRDD NOT LIKE '%13%') AND
(dbo.COL_V_Cost_GEMS_Detail.RRDD NOT LIKE '%2706%') AND (dbo.COL_V_Cost_GEMS_Detail.RRDD NOT LIKE '%2707%') AND
(dbo.COL_V_Cost_GEMS_Detail.RRDD NOT LIKE '%2331%')
GROUP BY dbo.COL_V_Cost_GEMS_Detail.TNG_SYS_NR, dbo.COL_TBL_VCOURSE_NEW.TNG_NA,
dbo.COL_TBL_VCOURSE_NEW.FCT_TYP_CD, dbo.COL_TBL_VCOURSE_NEW.DEP_TYP_CD, dbo.COL_TBL_VCOURSE_TYP.TNG_DESC,
dbo.COL_V_Cost_GEMS_Detail.JOB_FCT_CD, dbo.COL_V_Cost_GEMS_Detail.JOB_GRP_CD,
dbo.COL_V_Cost_GEMS_Detail.ST_COST_SUM + dbo.COL_V_Cost_GEMS_Detail.IN_COST_SUM
或者你可能想要总和:
SELECT dbo.COL_V_Cost_GEMS_Detail.TNG_SYS_NR AS [EHP Code], dbo.COL_TBL_VCOURSE_NEW.TNG_NA AS [Course Title],
dbo.COL_TBL_VCOURSE_NEW.FCT_TYP_CD + dbo.COL_TBL_VCOURSE_NEW.DEP_TYP_CD AS [Course Owner],
dbo.COL_TBL_VCOURSE_TYP.TNG_DESC AS [TYPE OF TRAINING], dbo.COL_V_Cost_GEMS_Detail.JOB_FCT_CD, dbo.COL_V_Cost_GEMS_Detail.JOB_GRP_CD,
dbo.COL_V_Cost_GEMS_Detail.ST_COST_SUM + dbo.COL_V_Cost_GEMS_Detail.IN_COST_SUM AS [Total Cost], SUM(dbo.COL_V_Cost_GEMS_Detail.STUDENTS)
AS SumOfSTUDENTS, SUM(dbo.COL_V_Cost_GEMS_Detail.INSTRUCTORS) AS SumOfINSTRUCTORS, SUM(dbo.COL_V_Cost_GEMS_Detail.ST_HOURS_SUM)
AS ST_HOURS, SUM(dbo.COL_V_Cost_GEMS_Detail.ST_COST_SUM) AS ST_COST, SUM(dbo.COL_V_Cost_GEMS_Detail.IN_HOURS_SUM) AS IN_HOURS,
SUM(dbo.COL_V_Cost_GEMS_Detail.IN_COST_SUM) AS IN_COST
FROM dbo.COL_V_Cost_GEMS_Detail INNER JOIN
dbo.COL_TBL_VCOURSE_NEW ON dbo.COL_V_Cost_GEMS_Detail.TNG_SYS_NR = dbo.COL_TBL_VCOURSE_NEW.TNG_SYS_NR INNER JOIN
dbo.COL_TBL_VCOURSE_TYP ON dbo.COL_TBL_VCOURSE_NEW.TNG_MDA_TYP_CD = dbo.COL_TBL_VCOURSE_TYP.TNG_TYP
WHERE (dbo.COL_V_Cost_GEMS_Detail.RRDD NOT LIKE '%12%') AND (dbo.COL_V_Cost_GEMS_Detail.RRDD NOT LIKE '%13%') AND
(dbo.COL_V_Cost_GEMS_Detail.RRDD NOT LIKE '%2706%') AND (dbo.COL_V_Cost_GEMS_Detail.RRDD NOT LIKE '%2707%') AND
(dbo.COL_V_Cost_GEMS_Detail.RRDD NOT LIKE '%2331%')
GROUP BY dbo.COL_V_Cost_GEMS_Detail.TNG_SYS_NR, dbo.COL_TBL_VCOURSE_NEW.TNG_NA,
dbo.COL_TBL_VCOURSE_NEW.FCT_TYP_CD + dbo.COL_TBL_VCOURSE_NEW.DEP_TYP_CD, dbo.COL_TBL_VCOURSE_TYP.TNG_DESC,
dbo.COL_V_Cost_GEMS_Detail.JOB_FCT_CD, dbo.COL_V_Cost_GEMS_Detail.JOB_GRP_CD,
dbo.COL_V_Cost_GEMS_Detail.ST_COST_SUM + dbo.COL_V_Cost_GEMS_Detail.IN_COST_SUM
答案 2 :(得分:1)
您正在使用& Bitwise operator来连接字符串。 String concatenation在SQL-Server中使用+
(或者您可以使用SQL-Server 2012,您可以使用CONCAT函数)
改变这个:
dbo.COL_TBL_VCOURSE_NEW.FCT_TYP_CD & dbo.COL_TBL_VCOURSE_NEW.DEP_TYP_CD,
要
dbo.COL_TBL_VCOURSE_NEW.FCT_TYP_CD + dbo.COL_TBL_VCOURSE_NEW.DEP_TYP_CD
在select语句和group by子句中。