we are able to query successfully from a Column called "ParentUUD" (without space) using query in python for MS ACCESS DB.

"SELECT Name FROM PartVersion WHERE ParentUUID='"+ str(lstUUID[0]) +"'"

we have a column whose name is "Parent UUID" (with space)
We are trying to query the column from PYTHON. we are getting error.I think the error is due to space in the column name.

Please tellus the method to query the MS access DB with column names with spaces.

This is not a Python issue, it is an Access issue. If you can perform the query in Access it will work through Python you just need to be careful as to how you format your query. If you paste the query that you would use from within Access, we can help.

Putting a quote around the field name works with SQLite. I don't know about MS Access. This is the well known example that has been changed to use a field name with a space in it (always a bad idea).

import sqlite3 as sqlite

##----------------------------------------------------------------------
def add_rec(cur, con):
   cur.execute("INSERT INTO test ('name last', age) values ('Putin',   50)")
   cur.execute("INSERT INTO test ('name last', age) values ('Putin',   50)")
   cur.execute("INSERT INTO test ('name last', age) values ('Putin',   50)")
   cur.execute("INSERT INTO test ('name last', age) values ('Yeltsin',   72)")
   cur.execute("INSERT INTO test ('name last', age) values ('Baby',   1)")

   con.commit()

#==========================================================================
if __name__ == "__main__":
   con = sqlite.connect("test_db" )
   cur = con.cursor()

##--- Note: 'name last'
   cur.execute("CREATE TABLE test ('name last' VARCHAR(20), age INT)")

   add_rec(cur, con)           ## add some recs

   cur.execute('SELECT * FROM test')
   for row in cur:
      print "name =", row[0], " age =", row[1]
   
   print "select test"
   cur.execute('SELECT age FROM test where "name last"="Yeltsin"')
   for row in cur:
       print row
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.