How do I search for a ', ' and replace with ', '< CR>< LF> in SQL Server Management Studio's editor

ix0qys7i  于 2023-06-04  发布在  SQL Server
关注(0)|答案(6)|浏览(182)

I have a long query that I'd like to replace the , with a carriage return to put all the fields on their own line but I can't figure out how to do it in the editor. It wont be fool proof, but better than doing it by hand.

pod7payv

pod7payv1#

CTRL+H

Find what: ', ' (No Quotes)
Replace With: ', \n' (No Quotes)

Expand the Find options and tick the Use Regular Expressions checkbox.

fxnxkyjh

fxnxkyjh2#

do a find/replace. you want to find a , and replace with a ,\n (new line). to use \n check the box at the bottom called "Use:" and then from the dropdown choose "Regular expressions".

v7pvogib

v7pvogib3#

Check the 'Use regular expressions', search ro \, and replace it with ,\n

a11xaf1n

a11xaf1n4#

In SQL Server Management Studio (SSMS), use the find/replace box with the "Use Regular Expressions" box selected and replace , (comma character) with ,\r\n (comma carriage return line feed.)

The \r represents the escaped carriage return CHAR(13) character and the \n represents the escaped linefeed CHAR(10) character.

If you're doing the opposite of removing/replacing CR/LF characters you'll need to consider your file format. Some file types use only CR, others use only LF, and most Windows formats use CR + LF. So you may need to play with the replace of \r\n with just \r or just \n for those different formats.

3npbholx

3npbholx5#

In management studio 2017 there is a button with a little gear and square, if you hover over it it reads "Use Regular Expression". Select this and enter , for the find and ,\n for the replace.

ioekq8ef

ioekq8ef6#

I used Jason Punyon's answer, but needed to use \r\n instead of \n .

I was trying to replace carriage return followed by a comma with just a comma. So I ended up using Ctrl + H, clicking the 'Use Regular Expressions' box, then:

Find \r\n,

Replace with ,

相关问题