473,396 Members | 1,929 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

MYSQL where clause help!

Hello, I am using python to run mysql commands, however I don't think that should be a problem. When I am trying to select vales from a mysql talbe, I am having some trouble with the where clause. The vales DATETIME are all integer values around 38947. When I use the actual value 38947 it selects all 26 rows perfectly. however if I use a variable like thedate=38947, and then use the 'thedate' to select the values form the table, I get an error. really any help would be greatly appreciated, THANK YOU!



Expand|Select|Wrap|Line Numbers
  1. >>> c.execute('Select REF_LEVERAGE from Actual_Daily_Report Where DATETIME=38947')
  2. 26L
  3. >>> 
  4. >>> thedate=38947
  5. >>> c.execute('Select REF_LEVERAGE from Actual_Daily_Report Where DATETIME=thedate')
  6.  
  7.  
  8. Traceback (most recent call last):
  9.   File "<stdin>", line 1, in <module>
  10.   File "/usr/lib/pymodules/python2.6/MySQLdb/cursors.py", line 166, in execute
  11.     self.errorhandler(self, exc, value)
  12.   File "/usr/lib/pymodules/python2.6/MySQLdb/connections.py", line 35, in defaulterrorhandler
  13.     raise errorclass, errorvalue
  14. _mysql_exceptions.OperationalError: (1054, "Unknown column 'thedate' in 'where clause'")
  15.  
Aug 30 '10 #1
2 2022
Jerry Winston
145 Expert 100+
Everything in side the single quotes gets parsed as sql server query. Turning this line
Expand|Select|Wrap|Line Numbers
  1. c.execute('Select REF_LEVERAGE from Actual_Daily_Report Where DATETIME=thedate')
Into this:
Expand|Select|Wrap|Line Numbers
  1. SELECT REF_LEVERAGE FROM Actual_Daily_Report WHERE DATETIME=thedate
In the second code sample, thedate is viewed as a field name in the context of the overall TSQL query. To make this work. you need to concatenate the query string with the value from your variable. My Python is beyond rusty. You will be better served by members from the Python section.

Here's my ill-formed attempt at python code:
Expand|Select|Wrap|Line Numbers
  1. c.execute('Select REF_LEVERAGE from Actual_Daily_Report Where DATETIME=' + thedate)
Expand|Select|Wrap|Line Numbers
  1. c.execute('Select REF_LEVERAGE from Actual_Daily_Report Where DATETIME=' <<myPythonConcatenationOperator>> thedate)
Aug 30 '10 #2
Oralloy
988 Expert 512MB
I'm surprised at your representation of DATETIME.

Why an integer field, and not a native timestamp type field?
Aug 30 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Neil | last post by:
Hi, I hope this question isn't too far off topic....I'm almost at my wits end trying to figure this out. I have a Mysql database and I wish to automate the backup of the database because I...
5
by: duikboot | last post by:
Hi all, I'm trying to export a view tables from a Oracle database to a Mysql database. I create insert statements (they look alright), but it all goes wrong when I try to execute them in Mysql,...
0
by: Ola Ogunneye | last post by:
--=_7B255FAE.1F7E0C30 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Hello all, Let me start out by saying that I am still a newbie. I just freshly installed...
3
by: slash | last post by:
Hi , Im new to MySql and i have no idea how to convert a sql server user defined function to MySql. Can any one help me.. CREATE FUNCTION ChildCategories (@categoryId int, @taxId int,...
10
by: Krakatioison | last post by:
Hi everyone, can someone point me to download of an example for saving and retrieving to/from MYSQL database. Or did anyone of you tried this and could share your code with me. I've got some data...
2
by: RickyZane | last post by:
I need a little help with an assignment.... Basically I have a table with several PRODUCTS PRODUCT(P_ID, P_Name, P_Class, P_Price, Product_Supplier) Anyways.... I need to display:
1
by: six | last post by:
Hello, i'm trying to setup replication with mysql. the master server is "MySQL version 5.0.27" and the slave server is: "MySQL version 5.0.27". so there shouldn't be any issues here. when i...
0
by: edward_sanders | last post by:
Hi, This is a newbie question. I am using a text for learning php/mysql. I am using PHP 5.2.x and mysql 5. The example is that of a mysql database of jokes. Before we get to joins there is a...
2
by: vb2005matt | last post by:
i have just learned how to connect to a remote MySQL database, i need to search this database by the login field, find the desired login field, and display the users information in textboxes. The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.