主要资格:Varchar(20)
Qualification_Title:Varchar(100)
查询:
select distinct Main_Qualification,
Main_Qualification + ' '+ Qualification_Title As Main_Qual_Title
from dbo.IM_EN_Main_Qualifcation_with_title_vw
where College_Year = @College_Year
and Qualification_Title not Like '%CANX%'
order by Main_Qualification + ' '+ Qualification_Title
当我执行它时,我收到错误:
将varchar值'20PA'转换为数据类型smallint
时转换失败dbo.IM_EN_Main_Qualifcation_with_title_vw:
SELECT dbo.IM_EN_Main_Qualification_vw.College_Year, dbo.IM_EN_Main_Qualification_vw.Learner_ID,
dbo.IM_EN_Main_Qualification_vw.Main_Qualification_Code,
dbo.IM_EN_Main_Qualification_vw.IS_AS_Level_Umbrella,
dbo.IM_EN_Main_Qualification_vw.IS_A2_Level_Umbrella,
dbo.IM_EN_Main_Qualification_vw.Main_Qualification,
dbo.IM_LU_Qualifications_vw.Qualification_Title,
dbo.IM_LU_Qualifications_vw.Qualification_Mgmnt_Code_1,
dbo.IM_LU_Qualifications_vw.Section
,dbo.IM_LU_Qualifications_vw.Qualification_Mgmnt_Code_2
,dbo.IM_EN_Main_Qualification_vw.Code
FROM dbo.IM_EN_Main_Qualification_vw INNER JOIN
dbo.IM_LU_Qualifications_vw ON
dbo.IM_LU_Qualifications_vw.Qualification_Code = dbo.IM_EN_Main_Qualification_vw.Main_Qualification_Code AND
dbo.IM_LU_Qualifications_vw.Qualification_Year = dbo.IM_EN_Main_Qualification_vw.College_Year
[dbo]。[IM_EN_Main_Qualification_vw](我们从此视图获取Main_Qualification):
SELECT e.College_Year,
e.Learner_ID,
a.Code AS Main_Qualification_Code,
MAX(b.IS_AS_Level_Umbrella) AS IS_AS_Level_Umbrella,
MAX(b.IS_A2_Level_Umbrella) AS IS_A2_Level_Umbrella,
-- Not took MAX belkow because there were two people doing both AS and A2 Levels.
-- This will give them AS Level as Main Qualification.
MAX(CASE WHEN b.IS_AS_Level_Umbrella = 'Yes' THEN 'AS Level'
WHEN b.IS_A2_Level_Umbrella = 'Yes' THEN 'A2 Level'
ELSE a.Code END) AS Main_Qualification
,a.Code
FROM IM_EN_ENROLMENTS_VW e
INNER JOIN (
-- Join to the query that gets the qual with the maximum GLH
SELECT A.COLLEGE_YEAR,
A.LEARNER_ID,
MAX(A.CODE) AS CODE,
A.GLH
FROM (-- Get GKH of all Quals and join this to highest
-- GLH the student has beteewn all Quals
SELECT COLLEGE_YEAR,
LEARNER_ID,
CODE,
SUM(GLH) AS GLH
FROM DBO.IM_EN_ENROLMENTS_VW
WHERE (TYPE_OF_RECORD = 'Q')
AND (QUALIFICATION_MGMNT_CODE_1 NOT IN ('KS','TUT'))
AND (QUALIFICATION_MGMNT_CODE_3 NOT IN ('AD'))
AND (Code NOT LIKE ('%/N%'))
AND (Completion_Stat_Q19 <> '4')
GROUP BY COLLEGE_YEAR,LEARNER_ID,CODE) AS A
INNER JOIN (
-- Get the MAX GLH of all Quals
SELECT COLLEGE_YEAR,
LEARNER_ID,
MAX(GLH) AS MAXGLH
FROM (
-- Get GKH of all Quals
SELECT COLLEGE_YEAR,
LEARNER_ID,
CODE,
SUM(GLH) AS GLH
FROM DBO.IM_EN_ENROLMENTS_VW
WHERE (TYPE_OF_RECORD = 'Q')
AND (QUALIFICATION_MGMNT_CODE_1 NOT IN ('KS','TUT'))
AND (QUALIFICATION_MGMNT_CODE_3 NOT IN ('AD'))
AND (Code NOT LIKE ('%/N%'))
AND (Completion_Stat_Q19 <> '4')
GROUP BY COLLEGE_YEAR,LEARNER_ID,CODE) AS V
GROUP BY COLLEGE_YEAR,LEARNER_ID) AS B
ON A.COLLEGE_YEAR = B.COLLEGE_YEAR
AND A.LEARNER_ID = B.LEARNER_ID
AND A.GLH = B.MAXGLH
AND A.COLLEGE_YEAR = B.COLLEGE_YEAR
group by A.COLLEGE_YEAR,
A.LEARNER_ID,
A.GLH) AS a ON e.College_year = a.College_year AND e.Learner_ID = a.Learner_ID
LEFT JOIN (
-- Get AS and A2 Level Learners
SELECT College_Year,
Learner_Id,
Code,
dbo.IS_AS_Umbrella(College_Year, Code) AS IS_AS_Level_Umbrella,
dbo.IS_A2_Umbrella(College_Year, Code) AS IS_A2_Level_Umbrella
FROM IM_EN_ENROLMENTS_VW
WHERE (dbo.IS_AS_Umbrella(College_Year, Code) = 'Yes' OR dbo.IS_A2_Umbrella(College_Year, Code) = 'Yes')
AND Type_Of_Record = 'Q') AS b ON e.College_Year = b.College_year
AND e.Learner_ID = b.Learner_ID
GROUP BY
e.College_Year,
e.Learner_ID,
a.Code
IM_LU_Qualifications_vw(从此处获取Qualification_Title):
SELECT RTRIM(dbo.PRPHProvisionHeader.PRPH_Code) AS Qualification_Code,
CASE WHEN LEFT(PRPH_Code, 5) = 'S1500' OR PRPH_Code LIKE '15%' THEN 'Yes' ELSE 'No' END AS Is_AS_level,
RTRIM(dbo.PRPIProvisionInstance.PRPI_Title) AS Qualification_Title,
------------------------------
RTRIM(PRIL_Title) as Course_funding_Title,
PRPIProvisionInstance.PRPI_Status,
------------------------------
dbo.PRILILR.PRIL_Year AS Qualification_Year,
RTRIM(dbo.PRPHProvisionHeader.PRPH_ML1) AS Qualification_Mgmnt_Code_1,
dbo.IM_LU_Departments_vw.Department,
RTRIM(dbo.PRPHProvisionHeader.PRPH_ML2) AS Qualification_Mgmnt_Code_2,
CASE WHEN RTRIM(dbo.PRPIProvisionInstance.PRPI_Available_Enr) = 0 THEN 'N' ELSE 'Y' END AS Available,
dbo.IM_LU_Sections_vw.Section,
RTRIM(dbo.PRPHProvisionHeader.PRPH_ML3) AS Qualification_Mgmnt_Code_3,
RTRIM(dbo.PRPIProvisionInstance.PRPI_FT_PT) AS Qualification_FT_PT,
ISNULL(RTRIM(dbo.PRCOCoordinators.PRCO_Tutor), '') AS Coordinator_Code,
ISNULL(PRFSFeesTuition.PRFS_Fee_Amount, 0) AS Tuition_Fees,
/********* TUI24+FC ************ */
ISNULL(FullCost_24plus.PRFS_Fee_Amount, 0) AS FullCost_24plus_Fees,
---------------
ISNULL(PRFSFeesUniform.PRFS_Fee_Amount, 0) AS Uniform_Fees,
ISNULL(PRFSFeesKit.PRFS_Fee_Amount, 0) AS Kit,
--------------
ISNULL(PRFSFeesMaterials.PRFS_Fee_Amount, 0) AS Material_Fees,
------------------------Full Cost Material_Fees-----------------------------------------------------------
ISNULL(FullCostMaterialsFees.PRFS_Fee_Amount, 0) AS FullCost_Material_Fees,
/********* CRB ************ */
ISNULL(CRB_Fees.PRFS_Fee_Amount, 0) AS CRB,
----------------------------------------------------------------------------------------------------------
ISNULL(PRFSFeesExam.PRFS_Fee_Amount, 0) AS Exam_Fees,
ISNULL(PRFSFeesTrainingCredit.PRFS_Fee_Amount, 0) AS Training_Credit_TF,
ISNULL(PRFSFeesUserFee5.PRFS_Fee_Amount, 0) AS Police_Check_Fees,
ISNULL(PRFSFeesOverseas.PRFS_Fee_Amount, 0) AS Overseas_Fees,
RTRIM(ISNULL(dbo.PRTTTutors.PRTT_Tutor, '')) AS Tutor,
dbo.PERSstaff.PERS_Forename AS Course_Leader_Forename,
dbo.PERSstaff.PERS_Surname AS Course_Leader_Surname,
RTRIM(dbo.PERSstaff.PERS_Department_ML) AS Tutor_Department,
IM_LU_Departments_vw.Department AS Tutor_Department_Description,
dbo.PRPIProvisionInstance.PRPI_GLH_A32 AS Qualification_GLH,
-------------------- Columns swapped around ------------
dbo.PRILILR.PRIL_Hours_per_Week AS GLH_per_week,
dbo.PRILILR.PRIL_Annual_End_Date As Annual_End_Date,
dbo.PRILILR.PRIL_Annual_GLH AS Annual_GLH,
--dbo.PRPIProvisionInstance.PRPI_Hours_per_Week AS GLH_per_week,
--------------------------------------------------------------
dbo.PRPIProvisionInstance.PRPI_Length_Weeks AS Weeks_in_year,
dbo.PRPIProvisionInstance.PRPI_Start_Date_A27 AS Qualification_Start_Date,
dbo.PRPIProvisionInstance.PRPI_Exp_End_Date_A28 AS Qualification_End_Date,
dbo.PRILILR.PRIL_Annual_Start_Date as Annual_Start_Date,
-------------------- Columns swapped around ------------
--dbo.PRILILR.PRIL_Aim_A09 AS Qual_Aim,
dbo.PRPIProvisionInstance.PRPI_Aim AS Qual_Aim,
dbo.PRPIProvisionInstance.PRPI_Title AS Aim_Title,
--+++++++++++++++++++++++++++++++++++
------------------- Columns swapped around ------------
ISNULL(AV.FullLevel2Percent, 0) AS Full_Level2_Percentage,
ISNULL(AV.FullLevel3Percent, 0) AS Full_Level3_Percentage,
--ISNULL(dbo.LAAV_ALL_VALUES.LEVEL2_PERCENTAGE, 0) AS Full_Level2_Percentage,
--ISNULL(dbo.LAAV_ALL_VALUES.LEVEL3_PERCENTAGE, 0) AS Full_Level3_Percentage,
-------------------- Columns swapped around ------------
[dbo].[Core_LARS_LearningDelivery].NotionalNVQLevel AS NVQLevel,
[dbo].[Core_LARS_LearningDelivery].EntrySubLevel as Entry_SubLevel,
[dbo].[Core_LARS_LearningDelivery].AwardOrgCode AS Awarding_Body,
-- dbo.LAIM_AIMS.NOTIONAL_NVQ_LEVEL_CODE AS NVQLevel,
-- dbo.LAIM_AIMS.AWARDING_ORGANISATION AS Awarding_Body,
--£££££££££££££££
dbo.PRILILR.PRIL_Year_Of AS QUAL_Year_of_Qual,
RTRIM(PRFSFeesCostRecovery.PRFS_Nominal) AS Cost_Recovery_AC,
RTRIM(PRFSFeesTuition.PRFS_Nominal) AS Tuition_Fees_AC,
Cost_Centres.Cost_Centre,
/********* TUI24+FC ************ */
FC_Cost_Centres.FC_Cost_Centre,
RTRIM(PRFSFeesTrainingCredit.PRFS_Nominal) AS Training_Credit_AC,
RTRIM(PRFSFeesExam.PRFS_Nominal) AS Exam_Fees_AC,
RTRIM(PRFSFeesMaterials.PRFS_Nominal) AS Material_Fees_AC,
RTRIM(PRFSFeesRegn.PRFS_Nominal) AS Regn_Fee_AC,
dbo.PRILILR.PRIL_Funding_A10 AS FEFC_Fund_Q10,
dbo.GNCDgncodes.GNCD_Description AS Funding_Description,
dbo.PRPIProvisionInstance.PRPI_Max AS QUAL_Max_Size,
NULL AS National_Rate_1,
dbo.PRPIProvisionInstance.PRPI_Length_Years AS No_Of_Years,
dbo.PRPIProvisionInstance.PRPI_Instance AS Instance,
dbo.PRPHProvisionHeader.PRPH_Type,
dbo.PRPIProvisionInstance.PRPI_Code AS Qual_Instance_Code,
-- dbo.PRPIProvisionInstance.PRPI_MOA AS MOA_Code,
dbo.PRILILR.PRIL_Workplace_Learning AS WPL,
------------------- Columns swapped around ------------
-- dbo.ALL_ANNUAL_VALUES.SSA_TIER1_CODE AS Subject_sector_area,
CASE WHEN [dbo].[Core_LARS_LearningDelivery].SectorSubjectAreaTier1 > 0
THEN RIGHT('0' + CAST(CAST([dbo].[Core_LARS_LearningDelivery].SectorSubjectAreaTier1 AS INT) AS VARCHAR),2) END AS Subject_sector_area,
--£££££££££££££
dbo.PRILILR.PRIL_Title as Marketing_Title,
dbo.PRILILR.PRIL_Delivery_Postcode_A23,
------------------------------------------------
RTRIM(dbo.PRPHProvisionHeader.PRPH_Subject) as Sub_Section
------------------------------------------------
FROM dbo.PRILILR LEFT OUTER JOIN
dbo.PRPHProvisionHeader INNER JOIN
dbo.PRPIProvisionInstance ON
dbo.PRPHProvisionHeader.PRPH_Code = dbo.PRPIProvisionInstance.PRPI_Code LEFT OUTER JOIN
dbo.PRCOCoordinators ON dbo.PRPHProvisionHeader.PRPH_Code = dbo.PRCOCoordinators.PRCO_Code AND
dbo.PRPIProvisionInstance.PRPI_Instance = dbo.PRCOCoordinators.PRCO_Instance
LEFT OUTER JOIN
[dbo].[Core_LARS_LearningDelivery] ON dbo.PRPIProvisionInstance.PRPI_Aim COLLATE Latin1_General_CI_AS = [dbo].[Core_LARS_LearningDelivery].[LearnAimRef] LEFT OUTER JOIN
(SELECT [dbo].[Core_LARS_AnnualValue].*
FROM [dbo].[Core_LARS_AnnualValue] INNER JOIN
(SELECT [LearnAimRef], MAX([EffectiveFrom]) LatestDate
FROM [dbo].[Core_LARS_AnnualValue]
GROUP BY LearnAimRef) LatestAV ON LatestAV.LearnAimRef = [dbo].[Core_LARS_AnnualValue].[LearnAimRef] AND LatestAV.LatestDate = [dbo].[Core_LARS_AnnualValue].[EffectiveFrom]) AV ON dbo.PRPIProvisionInstance.PRPI_Aim COLLATE Latin1_General_CI_AS = AV.LearnAimRef LEFT OUTER JOIN
dbo.PRFSFees AS PRFSFeesTuition ON dbo.PRPHProvisionHeader.PRPH_Code = PRFSFeesTuition.PRFS_Code AND
dbo.PRPIProvisionInstance.PRPI_Instance = PRFSFeesTuition.PRFS_Instance AND PRFSFeesTuition.PRFS_Fee_Type = 'TUICF' --'TUI'
/********* TUI24+FC ************ */
LEFT OUTER JOIN
dbo.PRFSFees AS FullCost_24plus ON dbo.PRPHProvisionHeader.PRPH_Code = FullCost_24plus.PRFS_Code AND
dbo.PRPIProvisionInstance.PRPI_Instance = FullCost_24plus.PRFS_Instance AND (FullCost_24plus.PRFS_Fee_Type = 'TUI24+FC')
-----------------------
LEFT OUTER JOIN
dbo.PRFSFees AS PRFSFeesUniform ON dbo.PRPHProvisionHeader.PRPH_Code = PRFSFeesUniform.PRFS_Code AND
dbo.PRPIProvisionInstance.PRPI_Instance = PRFSFeesUniform.PRFS_Instance AND PRFSFeesUniform.PRFS_Fee_Type = 'UNIFORM'
LEFT OUTER JOIN
dbo.PRFSFees AS PRFSFeesKit ON dbo.PRPHProvisionHeader.PRPH_Code = PRFSFeesKit.PRFS_Code AND
dbo.PRPIProvisionInstance.PRPI_Instance = PRFSFeesKit.PRFS_Instance AND PRFSFeesKit.PRFS_Fee_Type = 'Kit'
--------------------
LEFT OUTER JOIN
dbo.PRFSFees AS PRFSFeesCostRecovery ON dbo.PRPHProvisionHeader.PRPH_Code = PRFSFeesCostRecovery.PRFS_Code AND
dbo.PRPIProvisionInstance.PRPI_Instance = PRFSFeesCostRecovery.PRFS_Instance AND
PRFSFeesCostRecovery.PRFS_Fee_Type = 'COST REC'
LEFT OUTER JOIN
dbo.PRFSFees AS PRFSFeesMaterials ON dbo.PRPHProvisionHeader.PRPH_Code = PRFSFeesMaterials.PRFS_Code AND
dbo.PRPIProvisionInstance.PRPI_Instance = PRFSFeesMaterials.PRFS_Instance AND PRFSFeesMaterials.PRFS_Fee_Type = 'MAT' LEFT OUTER JOIN
-----------------------------Full Cost Materials Fees---------------------------------------------------------------------------------------------------
dbo.PRFSFees AS FullCostMaterialsFees ON dbo.PRPHProvisionHeader.PRPH_Code = FullCostMaterialsFees.PRFS_Code AND
dbo.PRPIProvisionInstance.PRPI_Instance = FullCostMaterialsFees.PRFS_Instance AND FullCostMaterialsFees.PRFS_Fee_Type = 'MATCF' LEFT OUTER JOIN
-----------------------------CRB Fees---------------------------------------------------------------------------------------------------
dbo.PRFSFees AS CRB_Fees ON dbo.PRPHProvisionHeader.PRPH_Code = CRB_Fees.PRFS_Code AND
dbo.PRPIProvisionInstance.PRPI_Instance = CRB_Fees.PRFS_Instance AND CRB_Fees.PRFS_Fee_Type = 'UCF5' LEFT OUTER JOIN
--------------------------------------------------------------------------------------------------------------------------------------------------------
dbo.PRFSFees AS PRFSFeesExam ON dbo.PRPHProvisionHeader.PRPH_Code = PRFSFeesExam.PRFS_Code AND
dbo.PRPIProvisionInstance.PRPI_Instance = PRFSFeesExam.PRFS_Instance AND PRFSFeesExam.PRFS_Fee_Type = 'EXM' LEFT OUTER JOIN
dbo.PRFSFees AS PRFSFeesTrainingCredit ON dbo.PRPHProvisionHeader.PRPH_Code = PRFSFeesTrainingCredit.PRFS_Code AND
dbo.PRPIProvisionInstance.PRPI_Instance = PRFSFeesTrainingCredit.PRFS_Instance AND
PRFSFeesTrainingCredit.PRFS_Fee_Type = 'TRAIN CRED' LEFT OUTER JOIN
dbo.PRFSFees AS PRFSFeesOverseas ON dbo.PRPHProvisionHeader.PRPH_Code = PRFSFeesOverseas.PRFS_Code AND
dbo.PRPIProvisionInstance.PRPI_Instance = PRFSFeesOverseas.PRFS_Instance AND
PRFSFeesOverseas.PRFS_Fee_Type = 'NONEU' LEFT OUTER JOIN
dbo.PRFSFees AS PRFSFeesRegn ON dbo.PRPHProvisionHeader.PRPH_Code = PRFSFeesRegn.PRFS_Code AND
dbo.PRPIProvisionInstance.PRPI_Instance = PRFSFeesRegn.PRFS_Instance AND PRFSFeesRegn.PRFS_Fee_Type = 'REG' LEFT OUTER JOIN
dbo.PRFSFees AS PRFSFeesUserFee5 ON dbo.PRPHProvisionHeader.PRPH_Code = PRFSFeesUserFee5.PRFS_Code AND
dbo.PRPIProvisionInstance.PRPI_Instance = PRFSFeesUserFee5.PRFS_Instance AND PRFSFeesUserFee5.PRFS_Fee_Type = 'UCF5' LEFT OUTER JOIN
dbo.PRTTTutors ON dbo.PRPHProvisionHeader.PRPH_Code = dbo.PRTTTutors.PRTT_Code AND
dbo.PRPIProvisionInstance.PRPI_Instance = dbo.PRTTTutors.PRTT_Instance LEFT OUTER JOIN
dbo.PERSstaff ON dbo.PRTTTutors.PRTT_Tutor = dbo.PERSstaff.PERS_Staff_Code LEFT OUTER JOIN
dbo.IM_LU_Sections_vw ON dbo.PRPHProvisionHeader.PRPH_ML2 = dbo.IM_LU_Sections_vw.Section_Code LEFT OUTER JOIN
dbo.IM_LU_Departments_vw ON dbo.PRPHProvisionHeader.PRPH_ML1 = dbo.IM_LU_Departments_vw.Department_Code LEFT OUTER JOIN
dbo.IM_LU_Departments_vw AS IM_LU_Departments_vw1 ON dbo.PERSstaff.PERS_Department_ML = IM_LU_Departments_vw1.Department_Code ON
dbo.PRILILR.PRIL_Code = dbo.PRPHProvisionHeader.PRPH_Code AND
dbo.PRILILR.PRIL_Instance = dbo.PRPIProvisionInstance.PRPI_Instance LEFT OUTER JOIN
dbo.GNCDgncodes ON dbo.GNCDgncodes.GNCD_General_Code = dbo.PRILILR.PRIL_Funding_A10 AND
dbo.GNCDgncodes.GNCD_Code_Type = 'CH' AND dbo.GNCDgncodes.GNCD_Level <= 98 LEFT OUTER JOIN
(SELECT PRFS_Code AS Code, PRFS_Instance AS Instance, RTRIM(PRFS_Finance_Dept) AS Cost_Centre
FROM dbo.PRFSFees
WHERE (PRFS_Fee_Type = 'TUICF')--'TUI'
GROUP BY PRFS_Code, PRFS_Instance, PRFS_Finance_Dept) AS Cost_Centres ON
dbo.PRPHProvisionHeader.PRPH_Code = Cost_Centres.Code AND dbo.PRPIProvisionInstance.PRPI_Instance = Cost_Centres.Instance
/********* TUI24+FC ************ */
LEFT OUTER JOIN
(SELECT PRFS_Code AS Code, PRFS_Instance AS Instance, RTRIM(PRFS_Finance_Dept) AS FC_Cost_Centre
FROM dbo.PRFSFees
WHERE (PRFS_Fee_Type = ('TUI24+FC'))--'TUI'
GROUP BY PRFS_Code, PRFS_Instance, PRFS_Finance_Dept) AS FC_Cost_Centres ON
dbo.PRPHProvisionHeader.PRPH_Code = FC_Cost_Centres.Code
AND dbo.PRPIProvisionInstance.PRPI_Instance = FC_Cost_Centres.Instance
-------------------
WHERE (dbo.PRPHProvisionHeader.PRPH_Type = 'Q')
感谢任何帮助。
谢谢, 的Ar
答案 0 :(得分:1)
您应该查看dbo.IM_EN_Main_Qualifcation_with_title_vw
。你的问题是你正在做类似
c1 + c2
其中c1和c2是列,c1是smallint
类型,c2是文本的,当创建视图时,c2只包含数值,但最近添加了一个文本数据,其中包含{{1} }。您需要使用CAST or CONVERT更改视图以将c1转换为文本数据。
修改
正如Aruna Raghuna指出的那样,它最终成为College_Year专栏中的一个问题,至少在一个案例中,而不是预期的数值包含文本。虽然我已经向我们展示了找到答案的方法,但坦率地说,正是Aruna搜索了这个问题。正在使用的思维过程如下: