Re: Using IF On 17 Dec, 13:04, Captain Paralytic <paul_laut...@yahoo.com> wrote:
> On 17 Dec, 13:01, UKuser <spiderc...@yahoo.co.uk> wrote:
>
>
>
> > On 17 Dec, 12:59, UKuser <spiderc...@yahoo.co.uk> wrote:
>
> > > On 17 Dec, 12:55, Captain Paralytic <paul_laut...@yahoo.com> wrote:
>
> > > > 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?
>
> > > Nothing particular - just a random date. Hopefully presented in the
> > > correct format.
>
> > Apologies - mis read ya. Ignore it for now - will look at it. Could
> > just use PHP and put it in the PHP code - just wondered if there was a
> > way to do it in mysql.
>
> Are you being deliberately stupid?
>
> I gave you the answer to your question in my first post on the subject
> thus:
> 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 I also pointed out that your original statements were faulty.
misread your script. Many thanks. |