Microsoft SQL Server:在需要条件的上下文中指定的非布尔类型的表达式,靠近"PSR_Labor"



我是SQL的新手,写了下面。我不明白我应该使用的布尔值。

SELECT 
ComponentName, 
Billed / 60 AS CustDecLaborHours, 
Labor / 60 AS ActualLaborHours
FROM 
ServiceCenter.Stage PSR_Labor
JOIN 
ServiceCenter.Stage PSR_Cost_Profit_Center ON ServiceCenter.Stage PSR_Labor.CostCenterID = ServiceCenter.Stage PSR_Cost_Profit_Center.CostCenterID
WHERE 
ProfitCenterFunctionId = '1000'

我试图研究解决方案,但我不知道布尔值应该在那里。 我也不确定问题是在 FROM 还是 ON。

SELECT 
ComponentName, 
Billed / 60 AS CustDecLaborHours, 
Labor / 60 AS ActualLaborHours
FROM 
ServiceCenter.Stage PSR_Labor
JOIN 
ServiceCenter.Stage PSR_Cost_Profit_Center ON ServiceCenter.Stage PSR_Labor.CostCenterID = ServiceCenter.Stage PSR_Cost_Profit_Center.CostCenterID
WHERE 
ProfitCenterFunctionId = '1000'

我希望将数据导入到 PowerBI 中。

很确定问题是你的表名中有空格。这不是一个好主意,但您可以使用名称周围的[方括号]来解决它。使用别名将有助于使查询更清晰。此外,应始终指定列属于哪个表。它可以防止不明确的错误,并有助于以后的调试。我猜到了列,但这样的事情应该非常接近。

SELECT cpc.ComponentName
, l.Billed / 60 AS CustDecLaborHours
, l.Labor / 60 AS ActualLaborHours
FROM ServiceCenter.[Stage PSR_Labor] l
JOIN ServiceCenter.[Stage PSR_Cost_Profit_Center] cpc
ON l.CostCenterID = cpc.CostCenterID
WHERE cpc.ProfitCenterFunctionId = '1000'

使用 [] 作为表名。 具有空格的表名。必须使用 []。

SELECT ComponentName, Billed / 60 AS CustDecLaborHours, Labor / 60 AS 
ActualLaborHours
FROM ServiceCenter.[Stage PSR_Labor]
JOIN ServiceCenter.[Stage PSR_Cost_Profit_Center]
ON ServiceCenter.[Stage PSR_Labor].CostCenterID = ServiceCenter.[Stage 
PSR_Cost_Profit_Center].CostCenterID
WHERE ProfitCenterFunctionId = '1000'

相关内容

最新更新