You combine whereClause3 and whereClause4 with the AND operator.
As gm70560 wrote, the variables workforceField, workforceindex are not defined. That's why, first you have to define them. I guess workforceindex is a double or at least a number datatype like farmfieldindex. So you have to Change:
whereClause3 = "\"%s\" = '%s'" % (workforceField, workforceindex)
to:
whereClause3 = "\"%s\" = %s" % (workforceField, workforceindex)
The whereClause4 is not defined (commented out). You have to change
whereClause = "\"%s\" = '%s'" % (farmField, farmfieldindex)
to:
whereClause4 = "\"%s\" = %s" % (farmField, farmfieldindex)
Is that right? (I removed the single quotes for the farmfieldindex)
Another reason for getting an error should be the following:
whereClause3 + "AND" + whereClause4
Is the same like: "\"%s\" = %s" + "AND" + "\"%s\" = %s"
Is the same like: "\"%s\" = %sAND\"%s\" = %s"
Thus, you have no blank between the value (workforceindex) of the first part of the where clause and the AND Operator. Change the Select Layer by Attribute Function to the following and it should work:
arcpy.SelectLayerByAttribute_management(countiesL, "NEW_SELECTION", whereClause3 + " AND " + whereClause4)
If it still not working check the delimiters in the where clause (have a look at the AddFieldDelimiters function)
You can use this structure to loop through the columns of a table.
Dim sCol As String
Dim aCol As Alias
Dim nCol As Integer
For nCol = 1 To TableInfo(sLayer, TAB_INFO_NCOLS)
sCol = ColumnInfo(sLayer, "COL" & nCol, COL_INFO_NAME)
aCol = sLayer & "." & sCol
Next
This will loop through the columns of the table sLayer and store the name in an Alias variable. The next step is to transfer the values from the column to a variable and to be able to write these to an SVG file for other systems to read them back.
To be able to do that in a nice manner you need to convert the data to something that will make sense to this other system.
Here is an example of how that can be done including the loop mentioned above:
Dim sCol As String
Dim aCol As Alias
Dim nCol As Integer
For nCol = 1 To TableInfo(sLayer, TAB_INFO_NCOLS)
sCol = ColumnInfo(sLayer, "COL" & nCol, COL_INFO_NAME)
aCol = sLayer & "." & sCol
sValue = ""
Do Case ColumnInfo(sLayer, sCol, COL_INFO_TYPE)
Case COL_TYPE_CHAR
sValue = aCol
Case COL_TYPE_INTEGER, COL_TYPE_SMALLINT, COL_TYPE_LOGICAL
sValue = Str$(aCol)
Case COL_TYPE_FLOAT, COL_TYPE_DECIMAL
'Converting decimal number to locale formatted numbers
'(Windows Regional Settings)
sValue = FormatNumber$(aCol)
Case COL_TYPE_DATE
If aCol Then
'Converting dates to locale formatted dates
'(Windows Regional Settings)
sValue = FormatDate$(aCol)
End If
Case COL_TYPE_TIME
If aCol Then
'Converting Time to 24 hour clock
sValue = FormatTime$(acol, "HH:mm:ss")
End If
Case COL_TYPE_DATETIME
If aCol Then
'Converting dates to locale formatted dates
'(Windows Regional Settings)
'Converting Time to 24 hour clock
sValue = FormatDate$(aCol) & " " & FormatTime$(GetTime(acol), "HH:mm:ss")
End If
End Case
Next
If you want to add a loop that runs through all the records of the layer too, you will have to wrap the loop above into another Do Until..Loop structure. In this structure, you use the Fetch statements to first fetch the first and then continue to fetch the next record until the cursor is at End Of Table (EOT).
Here's an example of that:
Dim sCol As String
Dim aCol As Alias
Dim nCol As Integer
Fetch First From sLayer
Do Until EOT(sLayer)
For nCol = 1 To TableInfo(sLayer, TAB_INFO_NCOLS)
sCol = ColumnInfo(sLayer, "COL" & nCol, COL_INFO_NAME)
aCol = sLayer & "." & sCol
sValue = ""
Do Case ColumnInfo(sLayer, sCol, COL_INFO_TYPE)
Case COL_TYPE_CHAR
sValue = aCol
Case COL_TYPE_INTEGER, COL_TYPE_SMALLINT, COL_TYPE_LOGICAL
sValue = Str$(aCol)
Case COL_TYPE_FLOAT, COL_TYPE_DECIMAL
'Converting decimal number to locale formatted numbers
'(Windows Regional Settings)
sValue = FormatNumber$(aCol)
Case COL_TYPE_DATE
If aCol Then
'Converting dates to locale formatted dates
'(Windows Regional Settings)
sValue = FormatDate$(aCol)
End If
Case COL_TYPE_TIME
If aCol Then
'Converting Time to 24 hour clock
sValue = FormatTime$(acol, "HH:mm:ss")
End If
Case COL_TYPE_DATETIME
If aCol Then
'Converting dates to locale formatted dates
'(Windows Regional Settings)
'Converting Time to 24 hour clock
sValue = FormatDate$(aCol) & " " & FormatTime$(GetTime(acol), "HH:mm:ss")
End If
End Case
Next
Fetch Next From sLayer
Loop
Hope that helps
Best Answer
You can do this easily with
string.join(iterable)
and not even worry about when to close the sql statementHere is a more readable version to get an idea of what is going on here.