Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
不明确的列名称错误SQL_Sql_Sql Server - Fatal编程技术网

不明确的列名称错误SQL

不明确的列名称错误SQL,sql,sql-server,Sql,Sql Server,我收到错误“不明确的列名”ClaimID,原因如下: USE ERSBI_Claims_Warehouse GO SELECT ClaimID AS vClaimID, DevelopmentTimeID AS vDevelopmentTimeID, UnderwritingYear AS vUnderwritingYear, IncurredClaimCount AS vIncurredClaimCount, Pa

我收到错误“不明确的列名”ClaimID,原因如下:

USE ERSBI_Claims_Warehouse
GO

SELECT 
    ClaimID             AS vClaimID,
    DevelopmentTimeID   AS vDevelopmentTimeID,
    UnderwritingYear    AS vUnderwritingYear,
    IncurredClaimCount  AS vIncurredClaimCount,
    PaidClaimCount      AS vPaidClaimCount,
    EstimateClaimCount  AS vEstimateClaimCount

FROM
    FactClaimSnapshotbreakdownClaimCount as fcbscc

INNER JOIN ERSBI_Warehouse.dbo.FactClaimAccidentYear AS fcay
    ON fcbscc.ClaimID = fcay.ClaimID

WHERE
    fcbscc.BreakdownIntermediateLevel = 'TPP'
AND UnderwritingYear > 2013

我对SQL非常陌生,但是我认为我已经包括了所有相关的表名。有人能告诉我哪里出了问题吗?提前谢谢

因为
ClaimID
存在于两个表中,您需要从中选择名称:

SELECT fcbscc.ClaimID ...

您在
SELECT
语句中只选择了
ClaimId
,但有多个表中有
ClaimId

你需要告诉它你是从哪张桌子拉过来的

根据您的加入:

fcbscc.ClaimID = fcay.ClaimID
要么

SELECT fcbscc.ClaimID 


就足够了

您应该养成在查询中总是在列名前面包含别名的习惯。它不仅消除了这个问题,而且使您更容易维护查询,因为您可以很容易地看到列属于哪个表。
SELECT fcay.ClaimID