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
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
I don't know the exact MS-syntax-dialect, but I'll try to prove that you don't need an IF or a CASE construct. I took @mellamokb 's reply as an example.
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
This is MS SQL. If you want to do more then just one command/select inside the if you do BEGIN .... END.
The idea here is to use the implication rewrite rule:
In your case
is equivalent to
and is itself equivalent to
Re-writing the original
ELSE
clause as anIF..THEN
statement in its own right:is equivalent to (this time omiting the intermediate step)
The two expression can then be writting in conjunctive normal form ("a series of
AND
s)