Thread: Using IF
View Single Post

   
  #4 (permalink)  
Old 02-28-2008, 10:30 AM
Captain Paralytic
 
Posts: n/a
Default Re: Using IF

On 17 Dec, 12:38, UKuser <spiderc...@yahoo.co.uk> wrote:
> On 17 Dec, 12:35, Captain Paralytic <paul_laut...@yahoo.com> wrote:
>
>
>
> > On 17 Dec, 12:17, UKuser <spiderc...@yahoo.co.uk> wrote:

>
> > > Hi,

>
> > > I'm not sure if I'm pursuing the wrong avenue, but here is my sql:

>
> > > SELECT *
> > > FROM user_table
> > > WHERE uuname='test'
> > > AND
> > > IF(CURDATE()>=DATE('2008-08-31')),
> > > CURDATE() <= DATE_ADD(start_date, INTERVAL 365 DAY),
> > > CURDATE() <= DATE('2008-12-31') AND start_date >=DATE('2008-08-31')
> > > )

>
> > > I want either of the statements to be appended to the where statement
> > > as long as they conform to the if statement.

>
> > > I get the error:
> > > Error Code : 1064
> > > You have an error in your SQL syntax; check the manual that
> > > corresponds to your MySQL server version for the right syntax to use
> > > near '),
> > > CURDATE() <= DATE_ADD(start_date, INTERVAL 365 DAY),
> > > CURDATE() <= DATE('2' at line 1

>
> > > Not quite sure whats wrong - please advise.

>
> > > Many thanks

>
> > > A

>
> > I think you want:
> > SELECT *
> > FROM user_table
> > WHERE uuname='test'
> > AND
> > (CURDATE()>=DATE('2008-08-31') AND CURDATE() <= DATE_ADD(start_date,
> > INTERVAL 365 DAY)
> > OR
> > (CURDATE() <= DATE('2008-12-31') AND start_date >=DATE('2008-08-31'))

>
> > But note that both cases could deal with the case where CURDATE() is
> > exactly '2008-12-31', is that what you want?

>
> Hi Captain,
>
> Basically I want it to execute one line if its after the 31st August
> 2008 and a different line if its before. So for example it would read
> "WHERE uuname='test' AND xxx-chosen line based on IF statement.
>
> A


But what if it is exactly 31st August 2008?
Reply With Quote