IF Condition in an SQL query

2020-03-12 06:39发布

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 MailDate is Tomorrow
Else
    SELECT *
    FROM table
    WHERE MailDate is Today

8条回答
欢心
2楼-- · 2020-03-12 07:34
IF DATEPART(HOUR, GETDATE()) > 16
BEGIN
    -- SELECT statement
END
ELSE 
BEGIN
    -- SELECT statement
END

It does not have to be in a stored procedure.

查看更多
Melony?
3楼-- · 2020-03-12 07:40

select a.name, if(a.is_active='t','Active','Inactive') from mytable a

查看更多
登录 后发表回答