tags:

views:

53

answers:

2
if (7/2/10 & 3/2/10) < 4/2/10    
begin
print ' ok'
end
else
begin
print 'not ok'
end

is like this can we use if condition is it possible But here in if condition i have changed whatever the dates but it only shows answer as " not ok " whether the condition is right or wrong it shows only "not ok" can some one help me

+1  A: 
  • Your code is SQL Server syntax, not MySQL. When I run it in SQL Server it prints 'not ok'. When I run it in MySQL I just get errors.
  • Dates in SQL server (and MySQL) should be in the format '2010-07-25'. Your expression is performing a division instead of handling dates.
  • It doesn't make sense to take the bitwise AND of two dates, but I have no idea what you are trying to do. Please explain in words.

My best guess is to change the first line to this:

IF '2010-02-07' < '2010-02-10' AND '2010-02-03' < '2010-02-10'

This produces output 'ok'.

Mark Byers
A: 

In SQL Server 2008 you could do this.

IF CAST('20100204' AS DATE)  > 
          ALL(SELECT D FROM (VALUES ('20100203'), ('20100207')) AS X (D))
BEGIN
PRINT ' ok'
END
ELSE
BEGIN
PRINT 'not ok'
END
Martin Smith