-1

我有一个为 SSRS 报告提供信息的 SQL 查询。该报告今天停止工作,我检查了查询,它也没有工作。我看不出查询有什么问题,但它不会运行。任何帮助将不胜感激,我今天真的需要将此报告重新在线,这是产生的错误:

Msg 8180, Level 16, State 1, Line 1
Statement(s) could not be prepared.
Msg 207, Level 16, State 1, Line 1
Invalid column name 'Expr2522'.
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "Tbl1172.ShortDescription" could not be bound.
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "Tbl1170.ShortDescription" could not be bound.
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "Tbl1168.ShortDescription" could not be bound.
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "Tbl1166.Exam" could not be bound.
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "Tbl1166.PVHigh" could not be bound.
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "Tbl1166.PVAch" could not be bound.
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "Tbl1166.PVComp" could not be bound.
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "Tbl1166.PVCont" could not be bound.
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "Tbl1166.PVFund" could not be bound.
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "Tbl1166.PVXfr" could not be bound.
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "Tbl1166.PVStart" could not be bound.
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "Tbl1166.PG_DifficultyOrDisabilityID" could not be bound.
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "Tbl1166.PG_EthnicityID" could not be bound.
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "Tbl1166.PG_SexID" could not be bound.
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "Tbl1166.ExpEndYrNumber" could not be bound.
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "Tbl1166.LR_MYSID" could not be bound.
Msg 207, Level 16, State 1, Line 1
Invalid column name 'Col5840'.
Msg 207, Level 16, State 1, Line 1
Invalid column name 'Col5843'.
Msg 207, Level 16, State 1, Line 1
Invalid column name 'Col5849'.

这是我的查询:

WITH All_Genders_LLDDs_Ethns as (SELECT
                                 Gender,
                                 LLDD,
                                 Ethnicity,
                                 PG_AgeBandID,
                                 AgeBand,
                                 AgeGroup

                                 FROM
                                 (SELECT 'Male' as Gender 
                                  UNION ALL SELECT 'Female' as Gender) as Genders,
                                 (SELECT 'LLDD' as LLDD 
                                  UNION ALL SELECT 'NO_LLDD' as LLDD) as LLDDs,
                                 (SELECT 'WB' as Ethnicity
                                  UNION ALL SELECT 'NWB' as Ethnicity) as Ethnicities,
                                 (SELECT DISTINCT
                                  PG_AgeBandID,
                                  ab.Description as AgeBand,
                                  ag.Description as AgeGroup

                                  FROM
                                  MSQL2.ProAchieve.dbo.LR_MYSHighByLevel l
                                  LEFT JOIN MSQL2.ProGeneral.dbo.AgeBand ab on l.PG_AgeBandID = ab.AgeBandID
                                  LEFT JOIN MSQL2.ProGeneral.dbo.AgeGroup ag on l.PG_AgeGroupID = ag.AgeGroupID

                                  WHERE
                                  l.PG_QType3ID not in ('30','40') and
                                  l.LR_MYSID in (SELECT 
                                                   Setting
                                                  FROM 
                                                  msql2.ProAchieve.dbo.SystemSetting
                                                  WHERE 
                                                  Code='DefaultLRSummary') AND 
                                  l.PG_ExpEndYrID IN ('11/12')) as AGE_Bands

                                 ),
    CoreProAchData as (SELECT
                        al.AgeBand,
                        al.AgeGroup,
                        lml.LR_MYSID,
                        al.Gender,
                        al.LLDD,
                        al.Ethnicity,
                        lml.EthnicityDetails,
                        lml.LDDetails,
                        lml.DisabilityDetails,
                        '' AS Details,
                        al.PG_AgeBandID,
                        lml.PG_ExpEndYrID,
                        lml.ExpEndYrNumber,
                        sum(lml.pvstart) as pvstart,
                        sum(lml.PVXfr) as PVXfr,
                        sum(lml.PVFund) as PVFund,
                        sum(lml.PVCont) as PVCont,
                        sum(lml.PVComp) as PVComp,
                        sum(lml.PVAch) as PVAch,
                        sum(lml.PVHigh) as PVHigh,
                        sum(lml.exam) as exam

                        FROM
                        All_Genders_LLDDs_Ethns al
                        LEFT JOIN (SELECT
                                   CASE WHEN l.PG_AgeGroupID = '1' THEN '16-18' ELSE '19+' END as AgeGroup,  
                                   CASE WHEN l.PG_SexID = 'M' THEN 'Male' ELSE 'Female' END as Gender,
                                   CASE WHEN l.PG_EthnicityID IN ('23','31') THEN 'WB' ELSE 'NWB' END as Ethnicity,
                                   CASE WHEN l.PG_DifficultyOrDisabilityID IN ('1') THEN 'LLDD' ELSE 'NO_LLDD' END as LLDD,
                                   e.ShortDescription AS EthnicityDetails,
                                   ld.ShortDescription AS LDDetails,
                                   d.ShortDescription AS DisabilityDetails,
                                   l.*

                                   FROM
                                   MSQL2.ProAchieve.dbo.LR_MYSHighByLevel l
                                   INNER JOIN MSQL2.ProGeneral.dbo.Ethnicity e ON e.EthnicityID = l.PG_EthnicityID
                                   INNER JOIN MSQL2.ProGeneral.dbo.LearningDifficulty ld ON ld.LearningDifficultyID = l.PG_LearningDifficultyID
                                   INNER JOIN MSQL2.ProGeneral.dbo.Disability d ON d.DisabilityID = l.PG_DisabilityID

                                   WHERE
                                   l.PG_QType3ID not in ('30','40') and
                                   l.LR_MYSID in (SELECT 
                                                  Setting
                                                  FROM 
                                                  msql2.ProAchieve.dbo.SystemSetting
                                                  WHERE 
                                                  Code='DefaultLRSummary') AND 
                                   l.PG_ExpEndYrID IN ('11/12')
                                   )lml on al.Gender = lml.Gender and
                                           al.LLDD = lml.LLDD and
                                           al.Ethnicity = lml.Ethnicity and
                                           al.PG_AgeBandID = lml.PG_AgeBandID


                        GROUP BY
                        al.AgeBand,
                        al.AgeGroup,
                        lml.LR_MYSID,
                        al.Gender,
                        al.LLDD,
                        al.Ethnicity,
                        lml.EthnicityDetails,
                        lml.LDDetails,
                        lml.DisabilityDetails,
                        al.PG_AgeBandID,
                        lml.PG_ExpEndYrID,
                        lml.ExpEndYrNumber)

SELECT
*
FROM
(
SELECT
--AgeBand,
--PG_AgeBandID,
AgeGroup,
'Gender' as Stat_Type,
Gender as Grouping_Val,
'' AS Details,
sum(isnull(pvstart,0)) as starts,
sum(isnull(PVXfr,0)) as transfers,
sum(isnull(PVFund,0)) as LSC_funded,
sum(isnull(PVCont,0)) as continuing,
sum(isnull(PVComp,0)) as completed,
sum(isnull(PVAch,0)) as achieved,
sum(isnull(PVHigh,0)) as highgrades,
sum(isnull(exam,0)) as exam_taken_not_know,
ReportingFramework.dbo.fsCIS_CalculatePercentages(sum(isnull(PVAch,0)) , sum(isnull(pvstart,0))) AS 'Success Rate',
ReportingFramework.dbo.fsCIS_CalculatePercentages(sum(isnull(PVComp,0)) + sum(isnull(PVCont,0)) , sum(pvstart)) AS 'Retention Rate',
ReportingFramework.dbo.fsCIS_CalculatePercentages(sum(isnull(PVAch,0)) , sum(isnull(pvcomp,0))) AS 'Achievment Rate'

FROM
CoreProAchData

GROUP BY
--AgeBand,
--PG_AgeBandID,
AgeGroup,
Gender

UNION ALL SELECT
--AgeBand,
--PG_AgeBandID,
AgeGroup,
'LLDD Break Down' as Stat_Type,
'Learning Difficulty'  as Grouping_Val,
LDDetails AS Details, 
sum(isnull(pvstart,0)) as starts,
sum(isnull(PVXfr,0)) as transfers,
sum(isnull(PVFund,0)) as LSC_funded,
sum(isnull(PVCont,0)) as continuing,
sum(isnull(PVComp,0)) as completed,
sum(isnull(PVAch,0)) as achieved,
sum(isnull(PVHigh,0)) as highgrades,
sum(isnull(exam,0)) as exam_taken_not_know,
ReportingFramework.dbo.fsCIS_CalculatePercentages(sum(isnull(PVAch,0)) , sum(isnull(pvstart,0))) AS 'Success Rate',
ReportingFramework.dbo.fsCIS_CalculatePercentages(sum(isnull(PVComp,0)) + sum(isnull(PVCont,0)) , sum(pvstart)) AS 'Retention Rate',
ReportingFramework.dbo.fsCIS_CalculatePercentages(sum(isnull(PVAch,0)) , sum(isnull(pvcomp,0))) AS 'Achievment Rate'

FROM
CoreProAchData

WHERE
LDDetails != 'none' AND
LDDetails != 'not known/not provided'

GROUP BY
--AgeBand,
--PG_AgeBandID,
AgeGroup,
LDDetails

UNION ALL SELECT
--AgeBand,
--PG_AgeBandID,
AgeGroup,
'LLDD Break Down' as Stat_Type,
'No Learning Difficulty'  as Grouping_Val,
LDDetails AS Details, 
sum(isnull(pvstart,0)) as starts,
sum(isnull(PVXfr,0)) as transfers,
sum(isnull(PVFund,0)) as LSC_funded,
sum(isnull(PVCont,0)) as continuing,
sum(isnull(PVComp,0)) as completed,
sum(isnull(PVAch,0)) as achieved,
sum(isnull(PVHigh,0)) as highgrades,
sum(isnull(exam,0)) as exam_taken_not_know,
ReportingFramework.dbo.fsCIS_CalculatePercentages(sum(isnull(PVAch,0)) , sum(isnull(pvstart,0))) AS 'Success Rate',
ReportingFramework.dbo.fsCIS_CalculatePercentages(sum(isnull(PVComp,0)) + sum(isnull(PVCont,0)) , sum(pvstart)) AS 'Retention Rate',
ReportingFramework.dbo.fsCIS_CalculatePercentages(sum(isnull(PVAch,0)) , sum(isnull(pvcomp,0))) AS 'Achievment Rate'

FROM
CoreProAchData

WHERE
LDDetails = 'none'

GROUP BY
--AgeBand,
--PG_AgeBandID,
AgeGroup,
LDDetails

UNION ALL SELECT
--AgeBand,
--PG_AgeBandID,
AgeGroup,
'LLDD Break Down' as Stat_Type,
'Unknown'  as Grouping_Val,
LDDetails AS Details, 
sum(isnull(pvstart,0)) as starts,
sum(isnull(PVXfr,0)) as transfers,
sum(isnull(PVFund,0)) as LSC_funded,
sum(isnull(PVCont,0)) as continuing,
sum(isnull(PVComp,0)) as completed,
sum(isnull(PVAch,0)) as achieved,
sum(isnull(PVHigh,0)) as highgrades,
sum(isnull(exam,0)) as exam_taken_not_know,
ReportingFramework.dbo.fsCIS_CalculatePercentages(sum(isnull(PVAch,0)) , sum(isnull(pvstart,0))) AS 'Success Rate',
ReportingFramework.dbo.fsCIS_CalculatePercentages(sum(isnull(PVComp,0)) + sum(isnull(PVCont,0)) , sum(pvstart)) AS 'Retention Rate',
ReportingFramework.dbo.fsCIS_CalculatePercentages(sum(isnull(PVAch,0)) , sum(isnull(pvcomp,0))) AS 'Achievment Rate'

FROM
CoreProAchData

WHERE
LDDetails = 'not known/not provided'

GROUP BY
--AgeBand,
--PG_AgeBandID,
AgeGroup,
LDDetails

UNION ALL SELECT
--AgeBand,
--PG_AgeBandID,
AgeGroup,
'LLDD Break Down' as Stat_Type,
'Disability'  as Grouping_Val,
DisabilityDetails AS Details, 
sum(isnull(pvstart,0)) as starts,
sum(isnull(PVXfr,0)) as transfers,
sum(isnull(PVFund,0)) as LSC_funded,
sum(isnull(PVCont,0)) as continuing,
sum(isnull(PVComp,0)) as completed,
sum(isnull(PVAch,0)) as achieved,
sum(isnull(PVHigh,0)) as highgrades,
sum(isnull(exam,0)) as exam_taken_not_know,
ReportingFramework.dbo.fsCIS_CalculatePercentages(sum(isnull(PVAch,0)) , sum(isnull(pvstart,0))) AS 'Success Rate',
ReportingFramework.dbo.fsCIS_CalculatePercentages(sum(isnull(PVComp,0)) + sum(isnull(PVCont,0)) , sum(pvstart)) AS 'Retention Rate',
ReportingFramework.dbo.fsCIS_CalculatePercentages(sum(isnull(PVAch,0)) , sum(isnull(pvcomp,0))) AS 'Achievment Rate'

FROM
CoreProAchData

WHERE
DisabilityDetails != 'no disability' AND
DisabilityDetails != 'not known/not provided'

GROUP BY
--AgeBand,
--PG_AgeBandID,
AgeGroup,
DisabilityDetails

UNION ALL SELECT
--AgeBand,
--PG_AgeBandID,
AgeGroup,
'LLDD Break Down' as Stat_Type,
'No Disability'  as Grouping_Val,
DisabilityDetails AS Details, 
sum(isnull(pvstart,0)) as starts,
sum(isnull(PVXfr,0)) as transfers,
sum(isnull(PVFund,0)) as LSC_funded,
sum(isnull(PVCont,0)) as continuing,
sum(isnull(PVComp,0)) as completed,
sum(isnull(PVAch,0)) as achieved,
sum(isnull(PVHigh,0)) as highgrades,
sum(isnull(exam,0)) as exam_taken_not_know,
ReportingFramework.dbo.fsCIS_CalculatePercentages(sum(isnull(PVAch,0)) , sum(isnull(pvstart,0))) AS 'Success Rate',
ReportingFramework.dbo.fsCIS_CalculatePercentages(sum(isnull(PVComp,0)) + sum(isnull(PVCont,0)) , sum(pvstart)) AS 'Retention Rate',
ReportingFramework.dbo.fsCIS_CalculatePercentages(sum(isnull(PVAch,0)) , sum(isnull(pvcomp,0))) AS 'Achievment Rate'

FROM
CoreProAchData

WHERE
DisabilityDetails = 'no disability'

GROUP BY
--AgeBand,
--PG_AgeBandID,
AgeGroup,
DisabilityDetails

UNION ALL SELECT
--AgeBand,
--PG_AgeBandID,
AgeGroup,
'LLDD Break Down' as Stat_Type,
'Unknown' as Grouping_Val,
DisabilityDetails AS Details, 
sum(isnull(pvstart,0)) as starts,
sum(isnull(PVXfr,0)) as transfers,
sum(isnull(PVFund,0)) as LSC_funded,
sum(isnull(PVCont,0)) as continuing,
sum(isnull(PVComp,0)) as completed,
sum(isnull(PVAch,0)) as achieved,
sum(isnull(PVHigh,0)) as highgrades,
sum(isnull(exam,0)) as exam_taken_not_know,
ReportingFramework.dbo.fsCIS_CalculatePercentages(sum(isnull(PVAch,0)) , sum(isnull(pvstart,0))) AS 'Success Rate',
ReportingFramework.dbo.fsCIS_CalculatePercentages(sum(isnull(PVComp,0)) + sum(isnull(PVCont,0)) , sum(pvstart)) AS 'Retention Rate',
ReportingFramework.dbo.fsCIS_CalculatePercentages(sum(isnull(PVAch,0)) , sum(isnull(pvcomp,0))) AS 'Achievment Rate'

FROM
CoreProAchData

WHERE
DisabilityDetails = 'not known/not provided'

GROUP BY
--AgeBand,
--PG_AgeBandID,
AgeGroup,
DisabilityDetails

UNION ALL SELECT
--AgeBand,
--PG_AgeBandID,
AgeGroup,
'LLDD' as Stat_Type,
CASE WHEN LLDD ='NO_LLDD' THEN 'No ' ELSE '' END + 'Learning Disability / Difficulty'  as Grouping_Val,
'' AS Details,
sum(isnull(pvstart,0)) as starts,
sum(isnull(PVXfr,0)) as transfers,
sum(isnull(PVFund,0)) as LSC_funded,
sum(isnull(PVCont,0)) as continuing,
sum(isnull(PVComp,0)) as completed,
sum(isnull(PVAch,0)) as achieved,
sum(isnull(PVHigh,0)) as highgrades,
sum(isnull(exam,0)) as exam_taken_not_know,
ReportingFramework.dbo.fsCIS_CalculatePercentages(sum(isnull(PVAch,0)) , sum(isnull(pvstart,0))) AS 'Success Rate',
ReportingFramework.dbo.fsCIS_CalculatePercentages(sum(isnull(PVComp,0)) + sum(isnull(PVCont,0)) , sum(pvstart)) AS 'Retention Rate',
ReportingFramework.dbo.fsCIS_CalculatePercentages(sum(isnull(PVAch,0)) , sum(isnull(pvcomp,0))) AS 'Achievment Rate'

FROM
CoreProAchData

GROUP BY
--AgeBand,
--PG_AgeBandID,
AgeGroup,
LLDD

UNION ALL SELECT
--AgeBand,
--PG_AgeBandID,
AgeGroup,
'Ethnicity' as Stat_Type,
CASE WHEN Ethnicity ='NWB' THEN 'Non ' ELSE '' END + 'White British' as Grouping_Val,
EthnicityDetails AS Details,
sum(isnull(pvstart,0)) as starts,
sum(isnull(PVXfr,0)) as transfers,
sum(isnull(PVFund,0)) as LSC_funded,
sum(isnull(PVCont,0)) as continuing,
sum(isnull(PVComp,0)) as completed,
sum(isnull(PVAch,0)) as achieved,
sum(isnull(PVHigh,0)) as highgrades,
sum(isnull(exam,0)) as exam_taken_not_know,
ReportingFramework.dbo.fsCIS_CalculatePercentages(sum(isnull(PVAch,0)) , sum(isnull(pvstart,0))) AS 'Success Rate',
ReportingFramework.dbo.fsCIS_CalculatePercentages(sum(isnull(PVComp,0)) + sum(isnull(PVCont,0)) , sum(pvstart)) AS 'Retention Rate',
ReportingFramework.dbo.fsCIS_CalculatePercentages(sum(isnull(PVAch,0)) , sum(isnull(pvcomp,0))) AS 'Achievment Rate'

FROM
CoreProAchData

GROUP BY
--AgeBand,
--PG_AgeBandID,
AgeGroup,
Ethnicity,
EthnicityDetails) as sub

ORDER BY
--convert(int,PG_AgeBandID),
Stat_Type,
Grouping_Val
4

2 回答 2

3

这有点猜测,但评论太长了。当收到长长的错误消息流时,查看第一个错误消息通常会有所帮助:

Msg 8180, Level 16, State 1, Line 1
Statement(s) could not be prepared.
Msg 207, Level 16, State 1, Line 1
Invalid column name 'Expr2522'.

expr2522嗯,这很奇怪,因为您的查询中没有调用列。这看起来也像是 SQL 编译器将包含在执行计划中的内容。

我的怀疑是数据库中发生了一些变化。我的建议是重新编译所有查询、存储过程、函数和视图。重新编译要么失败,要么给你一个更容易理解的错误信息。或者,它可能会将查询和视图调整为新的数据库结构,以便它们能够正常工作。

于 2013-05-02T13:58:08.497 回答
1

查询是否引用数据库中的任何视图?如果它们不是使用模式绑定创建的,那么底层数据库模式可能会更改,从而使视图无效。

函数 ReportingFramework.dbo.fsCIS_CalculatePercentages 也可能发生了变化。

简而言之,最可能的原因是数据库模式或相关功能或过程发生变化。您需要将查询分开并一次测试一个部分,以尝试识别导致它失败的部分。

我会从

SELECT TOP 100 * FROM CoreProAchData

看看这是否有效,然后从那里构建它。

于 2013-05-03T00:31:03.703 回答