Skip to content

Commit

Permalink
TSQL: Allow for multiple variables DECLAREd in the same statement (#1651
Browse files Browse the repository at this point in the history
)

Co-authored-by: jpersons <jpersons@iuhealth.org>
Co-authored-by: Barry Pollard <barry@tunetheweb.com>
  • Loading branch information
3 people committed Oct 14, 2021
1 parent a118069 commit e94158a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
14 changes: 10 additions & 4 deletions src/sqlfluff/dialects/dialect_tsql.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,16 +427,22 @@ class DeclareStatementSegment(BaseSegment):
match_grammar = Sequence(
"DECLARE",
Ref("ParameterNameSegment"),
AnyNumberOf(
Ref("ParameterNameSegment"),
Ref("CommaSegment", optional=True),
),
Ref("DatatypeSegment"),
Sequence(
Ref("EqualsSegment"),
Ref("ExpressionSegment"),
optional=True,
),
AnyNumberOf(
Ref("CommaSegment"),
Ref("ParameterNameSegment"),
Ref("DatatypeSegment"),
Sequence(
Ref("EqualsSegment"),
Ref("ExpressionSegment"),
optional=True,
),
),
Ref("DelimiterSegment", optional=True),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ BEGIN

DECLARE @DateNow DATE = GETDATE();

DECLARE @DateStart DATETIME2 = GETDATE()
,@DateEnd DATETIME2 = GETDATE()

DECLARE @EOMONTH DATE = ('1900-01-01')

SET @EOMONTH = ('2000-01-01')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# computed by SQLFluff when running the tests. Please run
# `python test/generate_parse_fixture_yml.py` to generate them after adding or
# altering SQL files.
_hash: 9f92368365708cb2c3720db344c9a1e4f43acb64808c7d59336769be0ff7932a
_hash: 338d1c94ba45eb2462a1cc04ba1d4418903d5d93ab0dbf9d33f098394e68c4c9
file:
batch:
create_procedure_statement:
Expand Down Expand Up @@ -32,6 +32,32 @@ file:
start_bracket: (
end_bracket: )
statement_terminator: ;
- statement:
declare_segment:
- keyword: DECLARE
- parameter: '@DateStart'
- data_type:
identifier: DATETIME2
- comparison_operator: '='
- expression:
function:
function_name:
function_name_identifier: GETDATE
bracketed:
start_bracket: (
end_bracket: )
- comma: ','
- parameter: '@DateEnd'
- data_type:
identifier: DATETIME2
- comparison_operator: '='
- expression:
function:
function_name:
function_name_identifier: GETDATE
bracketed:
start_bracket: (
end_bracket: )
- statement:
declare_segment:
keyword: DECLARE
Expand Down

0 comments on commit e94158a

Please sign in to comment.