diff --git a/src/languages/transactsql/transactsql.formatter.ts b/src/languages/transactsql/transactsql.formatter.ts index 01f6806cc7..bc4746ec2c 100644 --- a/src/languages/transactsql/transactsql.formatter.ts +++ b/src/languages/transactsql/transactsql.formatter.ts @@ -229,6 +229,7 @@ const reservedJoins = expandPhrases([ const reservedKeywordPhrases = expandPhrases([ 'ON {UPDATE | DELETE} [SET NULL | SET DEFAULT]', '{ROWS | RANGE} BETWEEN', + 'WITH TIES', ]); const reservedDataTypePhrases = expandPhrases([]); diff --git a/test/transactsql.test.ts b/test/transactsql.test.ts index f3041c23fe..3540c01490 100644 --- a/test/transactsql.test.ts +++ b/test/transactsql.test.ts @@ -258,6 +258,49 @@ describe('TransactSqlFormatter', () => { `); }); + // Issue #984 + it('formats TOP ... WITH TIES', () => { + expect( + format('select top (3) with ties name, score from players order by score desc;', { + keywordCase: 'upper', + }) + ).toBe(dedent` + SELECT + TOP (3) WITH TIES name, + score + FROM + players + ORDER BY + score DESC; + `); + }); + + it('formats TOP ... PERCENT WITH TIES', () => { + expect( + format('select top (10) percent with ties name from players order by score desc;', { + keywordCase: 'upper', + }) + ).toBe(dedent` + SELECT + TOP (10) PERCENT WITH TIES name + FROM + players + ORDER BY + score DESC; + `); + }); + + it('formats TOP n WITH TIES without parentheses', () => { + expect(format('SELECT TOP 5 WITH TIES name FROM players ORDER BY score;')).toBe(dedent` + SELECT + TOP 5 WITH TIES name + FROM + players + ORDER BY + score; + `); + }); + // Issue #877 it('allows the use of the ODBC date format', () => { const result = format(