1 Attachment(s)
VB - SQL Select Formatter
This is my SQL Select Formatter
It does not do checking, and there are bugs in formatting (wich I hope I'll fix soon).
One of the bug is that in certain cases, it does not place the closing bracket in the new line.
And another is that it does not do formatting for brackes in the 'FROM' block.
I think I'm gonna re-write the function SQLFormatRecurse, but until then I thought I'll post what I have for now.
To use the formatter, call the function FormatSQLSelect like this:
txtResult.Text = FormatSQLSelect(txtSource.txt)
Also note that you can input the Tab delimiter, the default is vbTab constant, but you can put spaces instead. To do that, call it like this:
txtResult.Text = FormatSQLSelect(txtSource.txt, " ")
or
txtResult.Text = FormatSQLSelect(txtSource.txt, Space(4))
Also, the function can format multiple Select statements in one call IF the statements are delimited by ";"
So you can format a string that contains (for example)
Code:
SELECT * FROM tbl_test1;
SELECT Count(*) FROM tbl_test2;
SELECT SUM(test) FROM tbl_numbers
the result will be:
Code:
SELECT *
FROM tbl_test1;
SELECT Count(*)
FROM tbl_test2;
SELECT SUM(test)
FROM tbl_numbers
Also check si_the_geek's formatter here: VB - SQL 'Select' statement formatter/checker
His formatter is better than mine, but he's using a different style of formatting.
Re: VB - SQL Select Formatter
The comment like /**/ and -- can not be formatted.
Re: VB - SQL Select Formatter
Try si_the_geek's formatter here: VB - SQL 'Select' statement formatter/checker, it's better than mine, though I don't know if he made it work for comments. I did not have time to improve my SQL formatter.
Re: VB - SQL Select Formatter
Great idea!
I wondering if this code can be compiled as a stand alone command line executable?
Do you think it can be possible?
Thanks
B
Re: VB - SQL Select Formatter
If it's a command line executable, how do you plan to pass (and get) the SQL query ?
Re: VB - SQL Select Formatter
maybe pointing the input file name and the output file name as input parameters ;)
Re: VB - SQL Select Formatter
So what is stopping you from doing that ?
You don't know how to get the execution parameters ?
You don't know how to read & write to a file ?
That's basically all you need...
Re: VB - SQL Select Formatter
I will do and let you know how goes
Your project is amazing
:thumb:
Thanks.
B.