AnsweredAssumed Answered

Where clause for '\n'

Question asked by jborgion Champion on Feb 4, 2019
Latest reply on Feb 12, 2019 by jborgion

ArcGIS 10.5.1 Python 2.7, enterprise geodatabse, SQL server back end

 

Using an arcpy.da.SearchCursor() how might I set up a where statement that looks for '\n'  newline special character? Here is one of my iterations that does not work:

 

fields = ['NOTES']
where = '{} like %\n%'.format(fields[0])
with arcpy.da.SearchCursor("pweng.SLCOEN.BacteriaBatch",fields,where) as cursor:
...     for row in cursor:
...         print row[0]
...        
Runtime error
Traceback (most recent call last):
  File "<string>", line 2, in <module>
RuntimeError: Underlying DBMS error [[Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Incorrect syntax near ')'.] [pweng.SLCOEN.BacteriaBatch]

 I've tried a few different iterations in the 'Select by Attributes' dialog in ArcMap, but haven't come across on that will return any records.  I had one record selected that I know has '\n' in the field, and it shows up nicely:

 

with arcpy.da.SearchCursor("pweng.SLCOEN.BacteriaBatch",fields) as cursor:
...     for row in cursor:
...         print row
...        
(u'Intensive\nFB-7:18',)

'''and'''

with arcpy.da.SearchCursor("pweng.SLCOEN.BacteriaBatch",fields) as cursor:
...     for row in cursor:
...         print row[0]
...        
Intensive
FB-7:18

 

This stems from a request associated with this post:  https://community.esri.com/message/829382-re-when-a-return-is-used-in-a-text-field-in-survey123-the-subsequent-multi-lin… 

Outcomes