Yes, this is a very successful way of creating an SQL query that is efficient.A keyfile type selection is often wanted, and the MakeQueryTable is buggy at 9.3 and has a lot of limitations.You have to have all features in the same geodatabase, complex expressions are not supported in file geodatabase and so on.Here is my workaround:Loop through the first table with a cursor to collect a list of keys.Pass it through a SET structure to remove duplicates.Create a (potentially huge) sql expressionUse this expression on the source featureclass to create a layerProcess or export the layer to a new featureclass# to make a keyfile
# 26 April 2010 kimo
# much better than MakeQueryTable and it works across geodatabases
# still uses an SQL query but python generates the set for the expression
# will work for tens of thousands of keys (amazing)
# if you want to save the featureclass or table as a layer or view definition
# to use in ArcMap (without making a copy) you MUST have an index on the key field
# or it will be extremely slow to draw.
# see the Keyfile tool in ArcScripts for an alternative method using selection sets in ArcMap
import arcgisscripting,sys,os,datetime,fileinput
gp = arcgisscripting.create(9.3)
def titlekey(title) :
gp.Workspace = ws
# Make a title set to use as a keyfile
lstTitle = []
cur = gp.SearchCursor(title)
row = cur.next()
while row :
lstTitle.append(row.ttl_title_no)
row = cur.next()
del row,cur
return set(lstTitle)
def title_tab(src) :
" use setTitle to export records to a table"
start = datetime.datetime.now()
gp.Workspace = ws
setTitle = titlekey(title)
expTitle = ",".join(["'"+t+"'" for t in setTitle])
sqlQuery = "ttl_title_no in ("+expTitle+")"
gp.MakeTableView_management(src,src+"_view",sqlQuery,wsout)
gp.OverwriteOutput = True
gp.CopyRows_management(src+"_view",wsout+"/"+src+"_sub")
print gp.GetCount(wsout+"/"+src+"_sub").Getoutput(0),"records in "+src+"_sub"
print datetime.datetime.now() - start
# ------------------------- main -------------------------
title = "e:/arrears.mdb/title"
ws = "e:/memo.gdb"
wsout = "e:/arrears.mdb"
# create subsets based on title keys
if not gp.Exists(wsout+"/tta_sub") :
title_tab("tta")