IF Condition in an SQL query

前端 未结 8 1637
长发绾君心
长发绾君心 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:46
    IF DATEPART(HOUR, GETDATE()) > 16
    BEGIN
        -- SELECT statement
    END
    ELSE 
    BEGIN
        -- SELECT statement
    END
    

    It does not have to be in a stored procedure.

    0 讨论(0)
  • 2021-01-04 20:54

    You need a stored procedure to do this in SQL. Have a look at the docs here http://msdn.microsoft.com/en-us/library/aa174792(v=sql.80).aspx

    0 讨论(0)
提交回复
热议问题