在计算字段中使用IF语句

时间:2015-09-15 08:29:49

标签: sql tsql if-statement

我正在尝试确定当前财政年度内的所有销售额,并希望将If语句合并为计算字段。请参阅下面的代码。

        SELECT        RtnUserId, COUNT(*) AS Returns_, RtnDt, COUNT(RtnDt) AS DtRet, 
            IF 
                BEGIN

                YEAR(RtnDt) = YEAR(GETDATE()) AND MONTH(RtnDt) >= 4 

                RETURN 'INDATE'

            END       as Financial_Period

        FROM            dbo.vw_AN_Admin_VendorReturns
        WHERE        (RtnUserId = 'BEND1') OR
                        (RtnUserId = 'DEENA') OR
                        (RtnUserId = 'RICHARDK2')
        GROUP BY RtnUserId, RtnDt, 

            IF 
                BEGIN
                YEAR(RtnDt) = YEAR(GETDATE()) AND MONTH(RtnDt) >= 4 

                RETURN'INDATE'

            END 

0 个答案:

没有答案