sql-formatter icon indicating copy to clipboard operation
sql-formatter copied to clipboard

treat `GO` as `;` if transactsql and split lines

Open bobbymannino opened this issue 4 months ago • 4 comments

If the language is TSQL, it is frequent that GO will be used instead of ;, especially in stored procedures, so it would be nice to have the option to set line splitters (maybe call them something better?) other then just ;, possible even comments could be, but for now this would be really nice in formatting the SQL to be prettier

bobbymannino avatar Oct 24 '25 08:10 bobbymannino

I'm not really sure I understand how you expect this to work. It would be better if you gave an example. Like how does SQL Formatter print GO right now and how would you like it to be treated instead?

nene avatar Oct 24 '25 09:10 nene

-- current behavior
set
ansi_nulls on
go
set
quoted_identifier on
go
create procedure aspDoSomething @pStartSerialNo varchar(20),
@pEndSerialNo varchar(20) as begin
-- code goes here
select 
  1;

end
go
-- desired behavior
set
ansi_nulls on
go -- line break after go

set
quoted_identifier on
go -- line break after go

create procedure aspDoSomething -- not in this issue but would be nice to split parameters of stored procedures and indent them, but thats a separate topic
  @pStartSerialNo varchar(20),
  @pEndSerialNo varchar(20) 
as 
begin
-- code goes here
select 
  1;

end
go -- line break after go

you cannot put GO with ; in a stored procedure file before create procedure x because it needs to be the first statement in a query (silly clause i know but thats SQL Server)

bobbymannino avatar Oct 24 '25 09:10 bobbymannino

OK. Thanks.

Basically should format GO on separate line (like now) and add an additional line break after it.

nene avatar Oct 24 '25 11:10 nene

yeah, i am pretty sure the keyword GO is only used in TSQL too (maybe that makes a difference?)

thank you @nene

bobbymannino avatar Oct 24 '25 13:10 bobbymannino