| | |
Some strange logical error in my code
Please support our MySQL advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Jan 2009
Posts: 3
Reputation:
Solved Threads: 0
Hi All,
I am mysql newbie.
Please have alook at this querry.
I am trying to run this querry but it is giving zero rows as output while I am running it on my table.
It was running fine a few days ago but started bugging around 7-8 days back when curdate and curdate+9 range was in January month it self.
I assume the problem is mainly due to change in month from January to February which is causing this trouble.
Is there any better way to code this.
I want to put a few variables where date is today or 9 days from today (that is for next ten days including today).
The date field has values 2009-01-30 for today in both the tables.
Also it is runs and gives output if I change
to
Although does not gives output for next 75 days but it does output for next 5 days.
Its a bit urgent
I am mysql newbie.
Please have alook at this querry.
sql Syntax (Toggle Plain Text)
SELECT b.DATE as DATE, a.tirthankar_name as tirthankar_name, a.kalyanak as kalyanak FROM table1 a, table2 b WHERE a.mass = b.mass AND a.paksh = b.paksh AND a.tithi = b.tithi AND b.DATE BETWEEN CURDATE( ) AND (CURDATE( ) +9) ORDER BY b.DATE LIMIT 0 , 1000;
I am trying to run this querry but it is giving zero rows as output while I am running it on my table.
It was running fine a few days ago but started bugging around 7-8 days back when curdate and curdate+9 range was in January month it self.
I assume the problem is mainly due to change in month from January to February which is causing this trouble.
Is there any better way to code this.
I want to put a few variables where date is today or 9 days from today (that is for next ten days including today).
The date field has values 2009-01-30 for today in both the tables.
Also it is runs and gives output if I change
sql Syntax (Toggle Plain Text)
"AND b.date BETWEEN CURdate( ) AND (CURdate( ) +9)"
sql Syntax (Toggle Plain Text)
"AND b.date BETWEEN CURdate( ) AND (CURdate( ) +75)"
Its a bit urgent
Last edited by peter_budo; Jan 30th, 2009 at 2:39 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
If you want the where to be contingent upon all the AND statements put them in parens.
eg:
eg:
sql Syntax (Toggle Plain Text)
WHERE ( AND a.paksh = b.paksh AND a.tithi = b.tithi AND b.DATE BETWEEN CURDATE( ) AND (CURDATE( ) +9) )
Last edited by peter_budo; Feb 2nd, 2009 at 7:09 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
A little clarification goes a long way.
•
•
Join Date: Jan 2009
Posts: 3
Reputation:
Solved Threads: 0
Thanks for suggestion. But it did not work as well.
I figured out while working that it is working like gives entries corresponding to tomorrow.
gives entries for day after tomorrow. similarly gives entries for twenty next days.
It suggest that the code is working with a shift of 69 in addition of Curdate().
Any clues for why this is happening.
I figured out while working that it is working like
MySQL Syntax (Toggle Plain Text)
CURDATE()+70
MySQL Syntax (Toggle Plain Text)
CURDATE()+71
MySQL Syntax (Toggle Plain Text)
CURDATE()+90
It suggest that the code is working with a shift of 69 in addition of Curdate().
Any clues for why this is happening.
sql Syntax (Toggle Plain Text)
AND b.DATE BETWEEN CURDATE( ) AND DATE_ADD(CURDATE(), INTERVAL +9 DAY)
Last edited by almostbob; Feb 10th, 2009 at 7:13 pm. Reason: dammit I cant spell
Failure is not an option It's included free
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it
Please mark solved problems, solved
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it
Please mark solved problems, solved
•
•
Join Date: Aug 2007
Posts: 165
Reputation:
Solved Threads: 18
No, not showing the definition. Rather, showing the current date. For example, on my desktop computer:
If there's an inexplicable discrepancy in the date, I would first check to be sure the SQL server's date is correct.
Upon finding the server's date is correct, I would RTFM and google until I found references to adding and offsetting dates. I would find that one can't simply add to curdate(). One needs to use, yes, another function:
or
Once the OP uses the correct functions, the code should begin to work.
MySQL Syntax (Toggle Plain Text)
mysql> SELECT CURDATE(); +------------+ | CURDATE() | +------------+ | 2009-02-10 | +------------+ 1 row IN SET (0.00 sec)
If there's an inexplicable discrepancy in the date, I would first check to be sure the SQL server's date is correct.
Upon finding the server's date is correct, I would RTFM and google until I found references to adding and offsetting dates. I would find that one can't simply add to curdate(). One needs to use, yes, another function:
MySQL Syntax (Toggle Plain Text)
mysql> SELECT DATE_ADD(CURDATE(), INTERVAL -11 DAY); +---------------------------------------+ | DATE_ADD(CURDATE(), INTERVAL -11 DAY) | +---------------------------------------+ | 2009-01-30 | +---------------------------------------+ 1 row IN SET (0.00 sec)
or
MySQL Syntax (Toggle Plain Text)
mysql> SELECT DATE_ADD(CURDATE(), INTERVAL +75 DAY); +---------------------------------------+ | DATE_ADD(CURDATE(), INTERVAL +75 DAY) | +---------------------------------------+ | 2009-04-26 | +---------------------------------------+ 1 row IN SET (0.00 sec)
Once the OP uses the correct functions, the code should begin to work.
•
•
Join Date: Jan 2009
Posts: 3
Reputation:
Solved Threads: 0
•
•
•
•
sql Syntax (Toggle Plain Text)
AND b.DATE BETWEEN CURDATE( ) AND DATE_ADD(CURDATE(), INTERVAL +9 DAY)
Thanks Bob (Almostbob) and all other for your help.
![]() |
Other Threads in the MySQL Forum
- Previous Thread: Query for 3 tables
- Next Thread: Count from multiple tables and group output by date
| Thread Tools | Search this Thread |
agplv3 alfresco amazon api artisticlicense aws bizspark breathalyzer camparingtocolumns changingprices cmg communityjournalism contentmanagement contractors copyright count court crm database design developer development distinct drupal dui ec2 email enterprise eudora facebook form foss gartner gnu government gpl greenit groklaw groupware hiring hyperic images innerjoins insert ip joebrockmeier join journalism keyword keywords kickfire laptop law legal license licensing linux maintenance managing mariadb matchingcolumns metron micromanage microsoft microsoftexchange mindtouch montywidenius mozilla music mysql mysqlcolumnupdating mysqldatetimeordermax() mysqlindex mysqlinternalqueries mysqlquery mysqlsearch news open-xchange opendatabasealliance opensource oracle penelope php priceupdating query referencedesign reorderingcolumns resultset saas select sharepoint simpledb sourcecode spotify sql sugarcrm syntax techsupport thunderbird transparency






