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 <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">'NOTES'</SPAN><SPAN class="punctuation token">]</SPAN>
where <SPAN class="operator token">=</SPAN> <SPAN class="string token">'{} like %\n%'</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>fields<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"pweng.SLCOEN.BacteriaBatch"</SPAN><SPAN class="punctuation token">,</SPAN>fields<SPAN class="punctuation token">,</SPAN>where<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> cursor<SPAN class="punctuation token">:</SPAN>
<SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> <SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> cursor<SPAN class="punctuation token">:</SPAN>
<SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> <SPAN class="keyword token">print</SPAN> row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN>
Runtime error
Traceback <SPAN class="punctuation token">(</SPAN>most recent call last<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
File <SPAN class="string token">"<string>"</SPAN><SPAN class="punctuation token">,</SPAN> line <SPAN class="number token">2</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">in</SPAN> <SPAN class="operator token"><</SPAN>module<SPAN class="operator token">></SPAN>
RuntimeError<SPAN class="punctuation token">:</SPAN> Underlying DBMS error <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">[</SPAN>Microsoft<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">[</SPAN>ODBC Driver <SPAN class="number token">13</SPAN> <SPAN class="keyword token">for</SPAN> SQL Server<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">[</SPAN>SQL Server<SPAN class="punctuation token">]</SPAN>Incorrect syntax near <SPAN class="string token">')'</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="punctuation token">[</SPAN>pweng<SPAN class="punctuation token">.</SPAN>SLCOEN<SPAN class="punctuation token">.</SPAN>BacteriaBatch<SPAN class="punctuation token">]</SPAN>
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN> 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
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>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…