I checked pymssql documents for parameters but I couldn't find what I was looking for. Basically when I execute the cursor with my SQL query, I always receive the list as comma separated. I'd like to change comma to another separator since some name fields contains comma. Is there a way to do that?
This is what I have:
cnxn = pymssql.connect(
server=db_server,
port=12345,
database='DataBase',
user=username,
password=password)
cursor = cnxn.cursor(as_dict=False)
#sql_statement = "SELECT Name FROM table"
cursor.execute(sql_statement)
rows=list(cursor.fetchall())
print(rows)
Output: [('Name,1', '20221110'), ('Name2', '20221115')]
What I need:
[('Name,1'|'20221110'), ('Name2'|'20221115')]
I'm making an assumption based on your comment about the need for a non-comma separator to avoid conflicts with the commas in your fields that you would be okay with something like this:
rows = [('Name,1', '20221110'), ('Name2', '20221115')]
for r in rows:
print("|".join(r))
Output:
Name,1|20221110
Name2|20221115
join
creates a single concatenated string from a collection of strings that are separated by the specified string.