IF Condition in an SQL query

前端 未结 8 1680
长发绾君心
长发绾君心 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:37

    IF ( DATEDIFF(h, GETDATE(), DATEADD(h,4,GETDATE()))>0 )
    
    SELECT *
    FROM table
    WHERE MailDate is Tomorrow
    
    ELSE
    
    SELECT *
    FROM table
    WHERE MailDate is Today
    

    This is MS SQL. If you want to do more then just one command/select inside the if you do BEGIN .... END.

提交回复
热议问题