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
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.