August 27, 2022 at 12:37 am
I am trying to find an easy way to vertically arrange numerous columns in a select statement using Find/Replace on regular expressions. While I am able to do it in such a way there is one single column of columns what I am not able to figure out is a a regular expression to create two columns of columns
Might be better with the below example -
SELECT [column 1], [Column A], [Column_2], [ColumnB], column3, column4, column5
I highlight only the columns and select regular expression on the Find/Replace window and replace all occurrences of a space using carriage return ,i.e, I replace ", " with ",\r". This returns a single column
What I am trying find is a regular expression that will create column pairs such below
SELECT [column 1], [Column A]
,[Column_2], [ColumnB]
,column3, column4
, column5
There is no purpose for this other than cleaning up the code visually and doing it in an efficient way when there are numerous columns on a single line. The regular expression should work on any character combination
August 28, 2022 at 1:10 am
Thanks for posting your issue and hopefully someone will answer soon.
This is an automated bump to increase visibility of your question.
August 30, 2022 at 8:20 pm
I've done some things using the "RegEx" button (which is a serious misnomer of it's own) on Search'n'Replace in SSMS but nothing like this. I can see other uses for doing things like this. Think of this as another "bump" for your good question and I seriously hope someone know of or can figure out a way to do this in SSMS.
--Jeff Moden
Change is inevitable... Change for the better is not.
August 30, 2022 at 10:29 pm
There’s nothing (that I’m aware of) that will do exactly that. If you have RedGate SQL Prompt, you can get close(ish) using a custom style format.
September 1, 2022 at 3:16 pm
I believe that this does close to what you are looking for. It can probably be massaged to do exactly what you want. The big problem is that the trailing ,
is included in the pattern, and there isn't an easy way to insert a \r
within the pattern, so you would need to do this in two steps or keep the trailing comma instead of converting to a leading comma.
Search string: (([^,]+, ){2}
Replacement string: $0\r
The {2}
searches for exactly two consecutive matches of the specified pattern. If you use $1
instead of $0
in the replacement string, it will use only the second match for the replacement.
Drew
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
September 1, 2022 at 3:58 pm
I would use an SSMS add-in like ApexSQL Refactor.
There is a free version of it here https://en.freedownloadmanager.org/Windows-PC/ApexSQL-Refactor-FREE.html
I think you only get a trial period with the current version from the Apex site so better to use the download above.
Or if you have a budget and don't mind paying for something I would get Redgate SQL Prompt.
September 2, 2022 at 8:55 am
I believe that this does close to what you are looking for. It can probably be massaged to do exactly what you want. The big problem is that the trailing
,
is included in the pattern, and there isn't an easy way to insert a\r
within the pattern, so you would need to do this in two steps or keep the trailing comma instead of converting to a leading comma.Search string:
(([^,]+, ){2}
Replacement string:
$0\r
The
{2}
searches for exactly two consecutive matches of the specified pattern. If you use$1
instead of$0
in the replacement string, it will use only the second match for the replacement.Drew
thanks !! this works fine for me. The trailing comma isn't a big issue
September 2, 2022 at 9:49 pm
I believe that this does close to what you are looking for. It can probably be massaged to do exactly what you want. The big problem is that the trailing
,
is included in the pattern, and there isn't an easy way to insert a\r
within the pattern, so you would need to do this in two steps or keep the trailing comma instead of converting to a leading comma.Search string:
(([^,]+, ){2}
Replacement string:
$0\r
The
{2}
searches for exactly two consecutive matches of the specified pattern. If you use$1
instead of$0
in the replacement string, it will use only the second match for the replacement.Drew
Awesome! Thanks, Drew.
--Jeff Moden
Change is inevitable... Change for the better is not.
September 17, 2022 at 7:46 pm
This was removed by the editor as SPAM
September 19, 2022 at 2:54 am
Jonathan AC Roberts wrote:I would use an SSMS add-in like ApexSQL Refactor.
There is a free version of it here https://en.freedownloadmanager.org/Windows-PC/ApexSQL-Refactor-FREE.html
I think you only get a trial period with the current version from the Apex site so better to use the download above.
Or if you have a budget and don't mind paying for something I would get Redgate SQL Prompt.
Thanks Man.
Considering what even some "paid for" software does (like hiding malware they didn't know about), I'm mighty leery about downloading and installing just about anything anymore. It's like playing volleyball in a mine field.
--Jeff Moden
Change is inevitable... Change for the better is not.
November 5, 2022 at 3:52 pm
This was removed by the editor as SPAM
November 5, 2022 at 5:46 pm
This was removed by the editor as SPAM
November 5, 2022 at 5:47 pm
This was removed by the editor as SPAM
November 5, 2022 at 5:49 pm
This was removed by the editor as SPAM
January 9, 2023 at 10:15 pm
I would use an SSMS add-in like ApexSQL Refactor.
There is a free version of it here https://en.freedownloadmanager.org/Windows-PC/ApexSQL-Refactor-FREE.html
I think you only get a trial period with the current version from the Apex site so better to use the download above.
Or if you have a budget and don't mind paying for something I would get Redgate SQL Prompt.
Is it work now days
Viewing 15 posts - 1 through 15 (of 16 total)
You must be logged in to reply to this topic. Login to reply