# Miscellaneous > General Database Discussions >  Free Online SQL Formatter

## damaha

We have just release  a free  Online SQL Formatter
which can beautify different sql dialects for you on the fly, 
and translate to other languages such as C#, Java,Delphi with many format options.

Try it here:
http://www.wangz.net/gsqlparser/sqlpp/sqlformat.htm

----------


## Rawhide

Nifty, but it doesn't remember the query I entered and if I try more than one way, it reformats the previously reformatted text. I think it would be better to have separate input and output windows.


Error Messages 
strcopy(1,1) expected token:BEGIN CLOSE DECLARE FETCH GOTO IF OPEN RETURN USE WHILE ALTER CREATE DELETE DROP INSERT SESSION SHARE USER SAVEPOINT 
") ;
strcopy(var1, "(4,0) expected token:BEGIN CLOSE DECLARE FETCH GOTO IF OPEN RETURN USE WHILE ALTER CREATE DELETE DROP INSERT SESSION SHARE USER SAVEPOINT 
" ;") ;
strcopy(var1, "(6,0) expected token:BEGIN CLOSE DECLARE FETCH GOTO IF OPEN RETURN USE WHILE ALTER CREATE DELETE DROP INSERT SESSION SHARE USER SAVEPOINT 
") ;
strcopy(var1, "(9,0) expected token:BEGIN CLOSE DECLARE FETCH GOTO IF OPEN RETURN USE WHILE ALTER CREATE DELETE DROP INSERT SESSION SHARE USER SAVEPOINT 
strcat(10,1) expected token:BEGIN CLOSE DECLARE FETCH GOTO IF OPEN RETURN USE WHILE ALTER CREATE DELETE DROP INSERT SESSION SHARE USER SAVEPOINT 
strcopy(12,1) expected token:BEGIN CLOSE DECLARE FETCH GOTO IF OPEN RETURN USE WHILE ALTER CREATE DELETE DROP INSERT SESSION SHARE USER SAVEPOINT 
strcopy(14,1) expected token:BEGIN CLOSE DECLARE FETCH GOTO IF OPEN RETURN USE WHILE ALTER CREATE DELETE DROP INSERT SESSION SHARE USER SAVEPOINT 
strcat(15,1) expected token:BEGIN CLOSE DECLARE FETCH GOTO IF OPEN RETURN USE WHILE ALTER CREATE DELETE DROP INSERT SESSION SHARE USER SAVEPOINT 
strcopy(17,1) expected token:BEGIN CLOSE DECLARE FETCH GOTO IF OPEN RETURN USE WHILE ALTER CREATE DELETE DROP INSERT SESSION SHARE USER SAVEPOINT 
strcat(18,1) expected token:BEGIN CLOSE DECLARE FETCH GOTO IF OPEN RETURN USE WHILE ALTER CREATE DELETE DROP INSERT SESSION SHARE USER SAVEPOINT 
strcopy(20,1) expected token:BEGIN CLOSE DECLARE FETCH GOTO IF OPEN RETURN USE WHILE ALTER CREATE DELETE DROP INSERT SESSION SHARE USER SAVEPOINT 
") ;
strcopy(var1, "(23,0) expected token:BEGIN CLOSE DECLARE FETCH GOTO IF OPEN RETURN USE WHILE ALTER CREATE DELETE DROP INSERT SESSION SHARE USER SAVEPOINT 
" ;") ;
strcopy(var1, "(25,0) expected token:BEGIN CLOSE DECLARE FETCH GOTO IF OPEN RETURN USE WHILE ALTER CREATE DELETE DROP INSERT SESSION SHARE USER SAVEPOINT 

If you have any comments or suggestion about this sql formatter,please contact us.

----------


## damaha

Thanks for your comments.

I have just added an output window for better use of this sql formatter.

----------


## Rawhide

Cool, that makes it much easier to use!!

One more slight suggestion. The output for ASP would be the same as it is for VB. So maybe you can make the output in the sleection box say "VB / ASP". If someone wanted to use it for ASP, they may not realize that the format is the same as VB.

----------


## damaha

I have updated this SQL Parser, and It formats SQL statements much better .
I will improve this parser continuously in the next several weeks.
anyone like to use this free online SQL Parser may bookmark this url 

http://www.wangz.net/gsqlparser/sqlpp/sqlformat.htm

----------


## MAK

Cool. Nice.

----------


## damaha

Ver2.0 is available. It's 50% faster than ver1 with
other format parameters.

http://www.wangz.net/gsqlparser/sqlpp/sqlformat.htm
--James

----------


## Gibbs

I think this works great, I have used it since the original from time to time for quick re-formatting and cleaning up..

I seem to recall an option to change the text delimiter from doubel quotes to single quotes....which is particular useful if trying to quick-like convert Access SQL to MS SQL

Great job on that formatter, it is extremely useful!

----------


## damaha

Html output of formatted SQL  is supported now, this feature
is very handy when you post SQL in forum or blogs, have a try:

http://www.wangz.net/gsqlparser/sqlpp/sqlformat.htm

----------


## Rawhide

Cool, this will come in very handy for the articles I write for other SQL Server sites. I have to submit them in HTMLS format, so it'll be nice to have something automatically output the proper font color tags.

----------


## damaha

There is also a SQL Formatter Plugin for Visual Studio,
maybe helpful to developers.

http://www.wangz.net/gsqlparser/sqlpp/sqlformat.htm

----------


## damaha

We have just updated our free online formatter, It's support
code-colored feature now, have a try here:

http://www.wangz.net/gsqlparser/sqlpp/sqlformat.htm

----------


## damaha

Free online formatter V2.6 is available now, support Common Table Expressions , CONTAINS/FREETEXT/CONTAINSTABLE/FREETEXTTABLE
and it's support DB2 Now.

have a try here:

http://www.wangz.net/gsqlparser/sqlpp/sqlformat.htm

----------


## jezemine

This is very cool!  I will definitely use this to fix some very messy sql left behind by contractors  :Smilie:

----------


## guidomarcel

There is also another SQL Formatter I published at www.sqlinform.com
Regards
GuidoMarcel

----------


## damaha

Try new version here:
http://www.wangz.net/gsqlparser/sqlpp/sqlformat.htm

and there are also add-ins for SQL Server Management Studio and Visual Studio 2005.

----------


## damaha

New version is available, better support for SQL Server 2005

http://www.wangz.net/gsqlparser/sqlpp/sqlformat.htm

----------


## MAK

Doesnt work for SQl Server 2005 syntax

CREATE TABLE AppUser
(
	UserID  int  NOT NULL identity(1,1) ,
	FirstName  varchar(100)  NOT NULL ,
	MiddleInitial  char(3)  NULL ,
	LastName  varchar(100)  NULL ,
	LoginName  varchar(100)  NULL ,
	UserDescription  varchar(100)  NULL ,
	Password  varchar(100)  NULL ,
	CustomerID  int  NULL ,
	CreatedDt  datetime constraint def_date_19 default getdate(),
	 PRIMARY KEY   CLUSTERED (UserID  ASC)
)



result:

/* Powered by General SQL Parser (www.sqlparser.com) */

ASC(12,36) expected token :Smilie:  ,

----------


## damaha

Thank you mak, we have fixed this bug in ver2.7.6

----------


## MAK

i believe you needed more testing for sql server 2005. Doesnt work for following code.

WITH DUPLICATE(ROW,GROUPROW,ID,FNAME,LNAME)
AS
(
SELECT ROW,GROUPROW= CASE WHEN ID=ID
THEN 
(SELECT COUNT(*) FROM (SELECT ROW_NUMBER() OVER (ORDER BY ID) AS ROW,
ID,LNAME,FNAME FROM MYTABLE
) AS A WHERE A.ID=B.ID AND
A.ROW<B.ROW)+1 END,ID,FNAME,LNAME FROM (SELECT ROW_NUMBER() OVER (ORDER 
BY ID) AS ROW,
ID,LNAME,FNAME FROM MYTABLE
)AS B
)
DELETE FROM DUPLICATE WHERE GROUPROW<>1

result:
/* Powered by General SQL Parser (www.sqlparser.com) */

DELETE(14,1) expected token :Frown:  , SELECT 



use master
go
Create Database MyDB_Snapshot1  on
(Name ='Mydb_Data',
FileName= 'C:\data\MyDB_Data.SS1')
AS SNAPSHOT of MyDB;
go

result:

/* Powered by General SQL Parser (www.sqlparser.com) */

Database(3,8) expected token:UNIQUE FUNCTION TRIGGER TABLE INDEX BITMAP GLOBAL LOCAL TEMPORARY VIEW PROCEDURE Name(4,2) expected token :Frown:  SELECT

----------


## damaha

Thank you.
sql server 2005 introduce more new syntax, I think we need more testing to have a better support

----------


## MAK

Good Luck and let us know when you are in good shape.

----------


## damaha

Hi all,
  I have just setup the new version.
  This new version support html output without change original
sql layout, or just modify case only. so it's very convenience if
you like to post your sql code to blogs/forums/wiki with colorful sql code which is more easy to read.

have a try of this free online sql formatter now!

http://www.wangz.net/gsqlparser/sqlpp/sqlformat.htm

--James

----------


## MAK

Looks very good. Still have diffculty in creating SQL Server 2005 syntax. eg:

use master
go
Create Database MyDB_Snapshot1 on
(Name ='Mydb_Data',
FileName= 'C:\data\MyDB_Data.SS1')
AS SNAPSHOT of MyDB;
go

----------

