ArcPy: MakeTable_View works in 10.2 but not in 10.3? Why?

1578
17
08-24-2016 03:59 PM
JoshuaChan
New Contributor III

I have a python script that is used as a toolbox that allows users to plug in a few variables and then a map is created for them, filtering the layers based on their input. It works fine in ArcMap 10.2 

But for some reason it has errors in ArcMap 10.3

where it bombs is the MakeTableView tool. The error statement is saying I have an improper SQL statement. 

What has changed from 10.2 to 10.3 that would make my SQL statement invalid?

Anyone know how to fix this? 

the end user wants to use 10.3

0 Kudos
17 Replies
DanPatterson_Retired
MVP Esteemed Contributor

I suspect that seeing the sql statement would help. You can also look through the change list and bug fixed list here, part way down the link

/blogs/dan_patterson/2016/05/09/the-links 

JoshuaChan
New Contributor III

good point... 

here's the print out of my SQL statement plus the error message: 

DISPOSITION_TRANSACTION_SID = 923413 AND PRIMARY_CONTACT_YRN = 'Y'
ERROR 000358: Invalid expression
Failed to execute (MakeTableView).

DISPOSITION_TRANSACTION_SID and PRIMARY_CONTACT_YRN are both fields in tables 

and the script runs fine when I run it in 10.2 but bombs in 10.3

Does it matter what version of ArcGIS the mxd was created in? the original one was probably 10.1.

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

the sql stuff is dependent on where the data resides... some queries like double-quotes around the field names, some square brackets, some doesn't matter... I think they all agree on single-quotes around strings as in 'Y'.

One thing that is not clear amongst the flavors is whether things separate by 'and' requires round brackets or not or whether and is AND or and (ie case).  So off you go to SQL reference for query expressions used in ArcGIS—Help | ArcGIS for Desktop and track down the source where the data resides to check the appropriate conditions for your data source.  You didn't indicate whether everything was the same between versions or not and I guess nothing popped up in the version change history.

JoshuaChan
New Contributor III

the data is sitting in ArcSDE and is the same data. It's only the ArcGIS version that's different (10.2 vs 10.3) 

in the past the SQL hasn't been an issue. I'll see if fiddling with double-single quotes helps or round/square/curly brackets helps or not.

when I remove that reference to that module that script works fine so it is something about the MakeTableView_Management tool that has changed or as you suggest, maybe something about how SQL needs to be formatted in 10.2 vs 10.3? 

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

What is the backend DBMS?

0 Kudos
JoshuaChan
New Contributor III

Oracle. Not sure what version. I can find out if the version of Oracle matters.

but that part remains the same... when I run in 10.2 or 10.3 it's still the same DBMS.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

I don't think the Oracle version will matter, but knowing it is Oracle may help troubleshoot.  Thanks.

0 Kudos
JoshuaChan
New Contributor III

unfortunately the double quotes around the field names didn't help. I also tried the square brackets.

I was looking earlier in my script and I have a SQL statement (using the same format) that I was using in a definition query on a layer (also stored in SDE) and that worked fine in both 10.2 and 10.3 

I was about to copy/paste my module (after adding double quotes) here but it looks like all formatting disappears (spaces, tabs etc). So here it is on an FTP site: 

ftp://ftp.geobc.gov.bc.ca/pub/outgoing/_SouthCoast_Region/clientNameModule.txt

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

I rarely use queries, but when I do, I find the python minilanguage useful for getting rid of those pesky pluses and backslashes and weird stuff.  try replacing the "" with[ ] and the like, I do like ( ) around sub queries and I would still check on the 'and' thing

>>> test = '("{}" = {}) AND ("{}" = \'Y\')'.format('a', 10, 'c')
>>> print(test)
("a" = 10) AND ("c" = 'Y')
0 Kudos