Results 1 to 8 of 8

Thread: VB - SQL Select Formatter

  1. #1

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

    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.

  2. #2
    New Member
    Join Date
    Feb 2009
    Posts
    1

    Re: VB - SQL Select Formatter

    The comment like /**/ and -- can not be formatted.

  3. #3

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

    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.

  4. #4
    New Member
    Join Date
    May 2011
    Posts
    15

    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

  5. #5

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

    Re: VB - SQL Select Formatter

    If it's a command line executable, how do you plan to pass (and get) the SQL query ?

  6. #6
    New Member
    Join Date
    May 2011
    Posts
    15

    Re: VB - SQL Select Formatter

    maybe pointing the input file name and the output file name as input parameters

  7. #7

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

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

  8. #8
    New Member
    Join Date
    May 2011
    Posts
    15

    Re: VB - SQL Select Formatter

    I will do and let you know how goes
    Your project is amazing


    Thanks.

    B.

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