Results 1 to 8 of 8

Thread: VB - SQL Select Formatter

Threaded View

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    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.
    Attached Files Attached Files
    Last edited by CVMichael; Nov 30th, 2005 at 11:02 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width