存储过程消息 8152

Stored procedure msg 8152

当 运行 我的存储过程时,出现此错误:

Msg 8152, Level 16, State 14, Procedure spCompReporting Detail, Line 26

我无法确定它的失败之处。

这是输出:

USE [DatabseName] 
GO DECLARE  *return_value int EXEC  @return_value = [dbo].[spCompReportingDetail1] 
@Date1 = N'12/01/14', 
@Date2 = N'12/10/14' SELECT 'Return Value' = @return_value 
GO

这是代码:

USE [DatabaseName]
GO
/****** Object:  StoredProcedure [dbo].[spCompReportingDetail1]    Script Date: 01/09/2015 11:23:54 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
ALTER PROCEDURE [dbo].[spCompReportingDetail1] 
/* 
    First Run.  Puts all in staging table.

    Need to add :
        Liability Removed
        TotalBenCharges
        BenChargesPaidDate
        RemainingBenCharges
*/


@Date1 as datetime,
@Date2 as datetime

AS
exec dbo.npCompReportingTablesCreate
SET ANSI_NULLS OFF

SET QUOTED_IDENTIFIER OFF



--delete from COMP_REPORT_DETAIL_STAGING

INSERT INTO COMP_REPORT_DETAIL_STAGING
                      (ClientID, ClientNumber, CompanyName, ClaimID, LastName, FirstName, SSN, PotentialBenefitCharge, CostCenterNumber, CostCenterDescription, 
                      RegionNumber, RegionDescription, DistrictNumber, DistrictDescription, ClaimDate, BYEDate, HireDate, LastDayWorked, SeparationCode, SepCodeDescr, 
                      SeparationReason, CurClaimStatus, HearingDate, HearingDecision, BoardAppealDate, BoardDecision)
SELECT     CLIENTS.ClientID, Clients.ClientNumber, COMPANY_NAMES.CompanyName, CLAIMS.ClaimID, CLAIMS.LastName, CLAIMS.FirstName, CLAIMS.SSN, 
                      CLAIMS.PotentialBenefitCharge,  COST_CENTERS.CostCenterNumber, COST_CENTERS.CostCenterDescription, 
                      REGIONS.RegionNumber, REGIONS.RegionDescription, DISTRICTS.DistrictNumber, DISTRICTS.DistrictDescription, CLAIMS.ClaimDate, CLAIMS.BYE, 
                      CLAIMS.HireDate, CLAIMS.LastDayWorked, SEPARATION_CODES.SeparationCode, SEPARATION_CODES.[Description] AS SepCodeDescr, 
                      SEPARATION_REASONS.SeparationReason, CUR_CLAIM_STATUS.CurClaimStatus, CLAIMS.HearingDate, DECISIONS_2.Decision AS HearingDecision, 
                      CLAIMS.BoardAppealDate, DECISIONS_1.Decision AS BoardDecision    
FROM         CLIENTS INNER JOIN
                      CLAIMS ON CLIENTS.ClientID = CLAIMS.ClientID INNER JOIN                      
                      COMPANY_NAMES ON CLIENTS.CompanyNameID = COMPANY_NAMES.CompanyNameID INNER JOIN
                      COST_CENTERS ON CLIENTS.ClientID = COST_CENTERS.ClientID AND CLAIMS.CostCenterID = COST_CENTERS.CostCenterID INNER JOIN
                      REGIONS ON CLIENTS.ClientID = REGIONS.ClientID AND COST_CENTERS.RegionID = REGIONS.RegionID INNER JOIN
                      DISTRICTS ON CLIENTS.ClientID = DISTRICTS.ClientID AND REGIONS.DistrictID = DISTRICTS.DistrictID INNER JOIN
                      SEPARATION_CODES ON CLAIMS.SeparationCodeID = SEPARATION_CODES.SeparationCodeID INNER JOIN
                      SEPARATION_REASONS ON CLAIMS.SeparationReasonID = SEPARATION_REASONS.SeparationReasonID AND 
                      SEPARATION_CODES.SeparationCodeID = SEPARATION_REASONS.SeparationCodeID INNER JOIN
                      CUR_CLAIM_STATUS ON CLAIMS.CurClaimStatusID = CUR_CLAIM_STATUS.CurClaimStatusID INNER JOIN
                      DECISIONS DECISIONS_1 ON CLAIMS.BoardDecisionID = DECISIONS_1.DecisionID INNER JOIN
                      DECISIONS DECISIONS_2 ON CLAIMS.HearingDecisionID = DECISIONS_2.DecisionID
WHERE        (CAST(CLAIMS.ClaimDate as datetime) between @Date1 AND @Date2)
ORDER BY   COMPANY_NAMES.CompanyName, CLAIMS.LastName, CLAIMS.FirstName


DELETE FROM COMP_REPORT_DETAIL_STAGING WHERE rtrim(ClientNumber) IN ('888', '999')   ------------------------------------------SPECIAL FOR COMP REPORT-----------------------------------------

UPDATE    COMP_REPORT_DETAIL_STAGING
SET              BenChargesPaidDate = (SELECT  MAX(DateOfCharge) FROM BENEFIT_CHARGES
                            WHERE BENEFIT_CHARGES.ClaimID = COMP_REPORT_DETAIL_STAGING.ClaimID)

UPDATE    COMP_REPORT_DETAIL_STAGING
SET              BenChargesPaidDate = convert(datetime, (cast(datepart(month, BenChargesPaidDate) as char) + '/' + cast(datepart(day, BenChargesPaidDate) as char) + '/' + cast(datepart(year, BenChargesPaidDate) as char)) )  


UPDATE    COMP_REPORT_DETAIL_STAGING
SET              TotalBenCharges = (SELECT SUM(cast(Charges as decimal))  
                FROM BENEFIT_CHARGES
                WHERE  BENEFIT_CHARGES.ClaimID = COMP_REPORT_DETAIL_STAGING.ClaimID)    



UPDATE    COMP_REPORT_DETAIL_STAGING
SET              TotalBenCharges = 0 WHERE TotalBenCharges = null

UPDATE    COMP_REPORT_DETAIL_STAGING
SET         LiabilityRemoved = PotentialBenefitCharge
WHERE   RTRIM(CurClaimStatus) = 'WON'

UPDATE    COMP_REPORT_DETAIL_STAGING
SET              LiabilityRemoved = 0 WHERE LiabilityRemoved < .01

UPDATE    COMP_REPORT_DETAIL_STAGING
SET              LiabilityRemoved = 0 WHERE LiabilityRemoved = null

UPDATE    COMP_REPORT_DETAIL_STAGING
SET              RemainingBenCharges = cast(PotentialBenefitCharge as dec) - cast(TotalBenCharges as dec) - cast(LiabilityRemoved as dec)




--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------



DELETE FROM COMP_REPORT_SUMMARY


DECLARE @Total  int
DECLARE @PT int
DECLARE @FC int
DECLARE @UC int

SET @Total =  (SELECT COUNT(*) FROM COMP_REPORT_DETAIL_STAGING)
SET @PT = (SELECT COUNT(*) FROM COMP_REPORT_DETAIL_STAGING WHERE RTRIM(CurClaimStatus) <> 'NON-PROTESTABLE')
SET @FC = (SELECT COUNT(*) FROM COMP_REPORT_DETAIL_STAGING WHERE RTRIM(CurClaimStatus) = 'WON')
SET @UC = (SELECT COUNT(*) FROM COMP_REPORT_DETAIL_STAGING WHERE RTRIM(CurClaimStatus) = 'LOST')

INSERT INTO COMP_REPORT_SUMMARY (TotalClaims) VALUES (@Total)   

----------UPDATE COMP_REPORT_SUMMARY  ----------------------------------------------------------------------------------------------------------------------- REMOVE FOR AGGREGATE REPORTS
----------SET   Client = (SELECT DISTINCT CompanyName FROM COMP_REPORT_DETAIL_STAGING)

UPDATE COMP_REPORT_SUMMARY
SET  FromDate = @Date1

UPDATE COMP_REPORT_SUMMARY
SET   ToDate = @Date2

UPDATE COMP_REPORT_SUMMARY
SET    ProtestableClaims = @PT

UPDATE COMP_REPORT_SUMMARY
SET     NonProtestableClaims = (SELECT COUNT(*) FROM COMP_REPORT_DETAIL_STAGING WHERE RTRIM(CurClaimStatus) = 'NON-PROTESTABLE')

UPDATE COMP_REPORT_SUMMARY
SET FavorableClaims = @FC

UPDATE COMP_REPORT_SUMMARY
SET UnfavorableClaims = @UC

IF @Total > 0 
    BEGIN
        UPDATE COMP_REPORT_SUMMARY
        SET ProtestableToTotal = CAST(ProtestableClaims as decimal) / CAST(TotalClaims as decimal)
    END

UPDATE COMP_REPORT_SUMMARY
SET PendingClaims = (SELECT COUNT(*) FROM COMP_REPORT_DETAIL_STAGING WHERE RTRIM(CurClaimStatus) = 'PENDING')

IF @PT > 0
    BEGIN
        UPDATE COMP_REPORT_SUMMARY
        SET PendingToProtestable = CAST(PendingClaims as decimal) / CAST(ProtestableClaims as decimal)
    END

IF @FC + @UC > 0
    BEGIN
        UPDATE COMP_REPORT_SUMMARY
        SET WinRatioProtestable = CAST(@FC as decimal) / (CAST(@FC as decimal) + CAST(@UC as decimal))
    END

UPDATE COMP_REPORT_SUMMARY
SET BoardAppeals = (SELECT COUNT(*) FROM COMP_REPORT_DETAIL_STAGING WHERE RTRIM(BoardAppealDate) <> '')

UPDATE COMP_REPORT_SUMMARY
SET Hearings = (SELECT COUNT(*) FROM COMP_REPORT_DETAIL_STAGING WHERE RTRIM(HearingDate) <> '')

UPDATE COMP_REPORT_SUMMARY
SET PotentialLiability = (SELECT SUM(PotentialBenefitCharge) FROM COMP_REPORT_DETAIL_STAGING)

UPDATE COMP_REPORT_SUMMARY
SET LiabilityRemoved = (SELECT SUM(LiabilityRemoved) FROM COMP_REPORT_DETAIL_STAGING)

UPDATE COMP_REPORT_SUMMARY
SET LiabilityRemaining = (SELECT SUM(RemainingBenCharges) FROM COMP_REPORT_DETAIL_STAGING)

UPDATE COMP_REPORT_SUMMARY
SET TotalCharges = (SELECT      SUM(BENEFIT_CHARGES.Charges) 
            FROM         BENEFIT_CHARGES INNER JOIN
                                  CLAIMS ON BENEFIT_CHARGES.ClaimID = CLAIMS.ClaimID INNER JOIN
                                  CLIENTS ON CLAIMS.ClientID = CLIENTS.ClientID
            WHERE        (CLIENTS.ClientID > 1000) AND (CAST(CLAIMS.ClaimDate as datetime) between @Date1 AND @Date2) 
                        AND (BENEFIT_CHARGES.Charges > 0))

UPDATE COMP_REPORT_SUMMARY
SET TotalCredits = (SELECT      SUM(BENEFIT_CHARGES.Charges) 
            FROM         BENEFIT_CHARGES INNER JOIN
                                  CLAIMS ON BENEFIT_CHARGES.ClaimID = CLAIMS.ClaimID INNER JOIN
                                  CLIENTS ON CLAIMS.ClientID = CLIENTS.ClientID
            WHERE        (CLIENTS.ClientID > 1000) AND (CAST(CLAIMS.ClaimDate as datetime) between @Date1 AND @Date2) 
                        AND (BENEFIT_CHARGES.Charges < 0))


SELECT COUNT(*) AS RC FROM COMP_REPORT_DETAIL_STAGING

该错误意味着您试图将一个值放入 table 中,该值大于该列可以容纳的值。 IE。您要将 varchar (100) 插入到定义为 varchar (80) 的列中。

注释掉插入语句的插入部分,运行 ssms 中的 proc 以确认 select 语句 returns。

希望对您有所帮助