在Telerik报告中将出生数据列作为年龄

时间:2015-04-20 08:56:36

标签: sql sql-server telerik telerik-mvc telerik-reporting

使用以下查询我正在

SELECT

        [tbl_HEI_student].[Gender], 
        [tbl_HEI_student].[Date_of_Birth],
        [tbl_HEI_student].[Programme_ID], 
        [tbl_hec_Programme].[ISCED_ID], 
        [tbl_hec_Programme].[Programme_ID] AS 'tbl_hec_ProgrammeProgramme_ID', 
        [tbl_hec_ISCED].[ISCED_ID] AS 'tbl_hec_ISCEDISCED_ID', 
        [tbl_hec_ISCED].[ISCED_Level]

    FROM (([tbl_HEI_student]
     FULL OUTER JOIN [tbl_hec_Programme]
     ON [tbl_HEI_student].[Programme_ID] = [tbl_hec_Programme].[Programme_ID])
     FULL OUTER JOIN [tbl_hec_ISCED]
     ON [tbl_hec_Programme].[ISCED_ID] = [tbl_hec_ISCED].[ISCED_ID])
    WHERE ([tbl_hec_Programme].[ISCED_ID]='5' or [tbl_hec_Programme].[ISCED_ID]='6' or [tbl_hec_Programme].[ISCED_ID]='7' or [tbl_hec_Programme].[ISCED_ID]='8')

这种报告

Fig:1

但我想计算年龄并进行分类。但我想在上面的查询中使用Date_of_Birth字段来完成此类报告

如何在查询级别

中执行此操作

enter image description here

1 个答案:

答案 0 :(得分:0)

您可以使用datdiff功能获取年龄,然后按

分组

select DateDiff(YEAR,'1984-04-21',getdate())年份

几个月的

select DateDiff(MONTH,'1991-01-21',getdate())/12

select DateDiff(DAY,'1984-04-21',getdate())/365

WITH ABC
AS (
    SELECT DateDiff(MONTH, '1984-04-21', getdate()) / 12 AS AGE
        ,'Arun' AS NAME

    UNION ALL

    SELECT DateDiff(MONTH, '1984-02-21', getdate()) / 12 AS AGE
        ,'Gorrv'

    UNION ALL

    SELECT DateDiff(MONTH, '1985-05-21', getdate()) / 12 AS AGE
        ,'Gorrv'

    UNION ALL

    SELECT DateDiff(MONTH, '1985-06-21', getdate()) / 12 AS AGE
        ,'Gorrv'

    UNION ALL

    SELECT DateDiff(MONTH, '1985-07-21', getdate()) / 12 AS AGE
        ,'Gorrv'

    UNION ALL

    SELECT DateDiff(MONTH, '1985-03-21', getdate()) / 12 AS AGE
        ,'Gorrv'

    UNION ALL

    SELECT DateDiff(MONTH, '1990-01-21', getdate()) / 12 AS AGE
        ,'Manu'

    UNION ALL

    SELECT DateDiff(MONTH, '1991-01-21', getdate()) / 12 AS AGE
        ,' Rishi'
    )
SELECT AGE
    ,Count(NAME)
FROM abc
GROUP BY Age