0

我想选择所有列但是如果燃料 = 1 则开始日期 > '1 oct 2013' 否则如果燃料 = 0 则开始日期 > '9 月 1 日'。

使用 SQL 服务器 2005。

我试过这个..

SELECT * FROM   EntitlementEpisode
WHERE
    IF EnFuel = 1
        THEN
            IF
                BEGIN
                    [EnEpisodeStart] > 
                    (SELECT TOP 1 [BeYearStart] 
                    FROM [BenefitYear] ORDER BY [BeId] desc)
                END
            ELSE IF EnFuel = 0
       THEN
            IF
                 BEGIN
                      [EnEpisodeStart] > 
                      CONVERT(VARCHAR(30), '1 OCT' + YEAR(GETDATE()))
            END

这是正确的方法吗?


使用二元运算符的力量......!

SELECT * 
FROM   EntitlementEpisode
WHERE
   (EnFuel=1 AND EnEpisodeStart] > 
                (SELECT TOP 1 [BeYearStart] 
                FROM [BenefitYear] ORDER BY [BeId] desc))

   OR

   (EnFuel=0 AND [EnEpisodeStart] > 
                  CONVERT(VARCHAR(30), '1 OCT' + YEAR(GETDATE())))
4

2 回答 2

3

使用二元运算符的力量......!

SELECT * 
FROM   EntitlementEpisode
WHERE
   (EnFuel=1 AND EnEpisodeStart] > 
                (SELECT TOP 1 [BeYearStart] 
                FROM [BenefitYear] ORDER BY [BeId] desc))

   OR

   (EnFuel=0 AND [EnEpisodeStart] > 
                  CONVERT(VARCHAR(30), '1 OCT' + YEAR(GETDATE())))
于 2013-07-24T12:38:11.030 回答
0

像这样的东西怎么样

SELECT  * 
FROM    EntitlementEpisode
WHERE   (EnFuel = 1 AND [EnEpisodeStart] > (SELECT TOP 1 [BeYearStart] FROM [BenefitYear] ORDER BY [BeId] desc)
OR      (EnFuel = 0 AND [EnEpisodeStart] > CONVERT(VARCHAR(30), '1 OCT' + YEAR(GETDATE())))
于 2013-07-24T12:38:33.610 回答