I have a post-deployment script that inserts/merges initial data to tables. I want to format insert script so that every row to be inserted will be of the same length. I want to be able to alt-click and select the same columns for every record.
Values inside insert statement are of formatted:
(123, 'File_X', 'ShortString'),
(124, 'File_XYZ', 'LoooonnnngString'),
What I'm trying to achieve is this format:
(123, 'File_X' , 'ShortString' ),
(124, 'File_XYZ', 'LoooonnnngString'),
I wasn't able to find any formatter that could be configured to achieve that.
I wrote it as a comment, but as suggested by @zimek-atomek I'll make it as an answer to be clearer.
To align all the columns in the file, you can use the plugin in for Visual Studio Code called Rainbow CSV (https://marketplace.visualstudio.com/items?itemName=mechatroner.rainbow-csv)
Since the file you are going to align contains commas (but it also support other delimiters), you can use the align columns
feature mentioned in the list at the beginning of the page.
UPDATE
Turns out there is a much easier way of doing this in Notepad++:
Old answer for posterity...
I don't know a way of automating this but it can be done fairly simply in Notepad++ as follows:
\h+
and in "Replace with" enter \t
(i.e. to replace each block of whitespace with a single tab).I have tried a silly way to solve your problem. First I am assuming that all the rows have three columns. Insert the scripts in a table and use below query to have them all formatted as you desire. ( I have created a table named scripts and inserted the scripts in script column)
with cte as (
select *,charindex (',',script) FirstSplit,
charindex (',',script,charindex (',',script)+1) SecondSplit,
charindex ('),',script,charindex (',',script,charindex (',',script)+1)+1) ThirdSplit
from scripts
),
cte2 as (select * ,max(firstsplit)over(order by (select null)) MaxFirstSplit,max(SecondSplit)over(order by (select null)) MaxSecondSplit ,max(ThirdSplit)over(order by (select null))MaxThirdSplit from cte)
select (substring(script,1,firstsplit-1)+space(maxfirstsplit-firstsplit)+',') +
(substring(script,FirstSplit+1,SecondSplit-FirstSplit-1)+space(MaxSecondSplit-SecondSplit-(MaxFirstSplit-FirstSplit))+',' )+
(substring(script,SecondSplit+1,ThirdSplit-SecondSplit-1)+space(MaxThirdSplit-ThirdSplit-(MaxSecondSplit-SecondSplit))+'),') NewScript
from cte2
Input:
script
(123, 'File_X', 'ShortString'),
(124, 'File_XYZ', 'LoooonnnngString'),
(124, 'File_XYZ', 'LgString'),
(124, 'F_XYZ', 'Lgring'),
(1, 'F_XYZ', 'Lgring'),
Output:
NewScript
(123, 'File_X' , 'ShortString' ),
(124, 'File_XYZ', 'LoooonnnngString'),
(124, 'File_XYZ', 'LgString' ),
(124, 'F_XYZ' , 'Lgring' ),
(1 , 'F_XYZ' , 'Lgring' ),
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With