IF Condition in an SQL query

前端 未结 8 1643
长发绾君心
长发绾君心 2021-01-04 20:23

I\'m a newbie to SQL Server. Please help me to write the following Logic in a query.

If getnow() > today 4 PM
Then
    SELECT *
    FROM table
    WHERE M         


        
8条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-04 20:39

    IF datepart(hh, getdate()) >= 16
        BEGIN
            SELECT *
            FROM table
            WHERE DateDiff(day, getdate(), MailDate) = 1
        END
    ELSE
        BEGIN
            SELECT *
            FROM table
            WHERE DateDiff(day, getdate(), MailDate) = 0
        END
    

提交回复
热议问题