Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TSQL: Allow for multiple statements in a procedure #1637

Merged
merged 5 commits into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/sqlfluff/dialects/dialect_tsql.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,9 +723,12 @@ class ProcedureDefinitionGrammar(BaseSegment):
type = "procedure_statement"
name = "procedure_statement"

match_grammar = OneOf(
Ref("StatementSegment"),
Ref("BeginEndSegment"),
match_grammar = AnyNumberOf(
OneOf(
Ref("BeginEndSegment"),
Ref("StatementSegment"),
),
min_times=1,
)


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CREATE PROC [Reporting].[PowerPlan] AS

DECLARE @DATEFUNCTION DATE = GETDATE()

BEGIN
SELECT 1
END
tunetheweb marked this conversation as resolved.
Show resolved Hide resolved
39 changes: 39 additions & 0 deletions test/fixtures/dialects/tsql/stored_procedured_mixed_statements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# YML test files are auto-generated from SQL files and should not be edited by
# hand. To help enforce this, the "hash" field in the file must match a hash
# 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: 36d43ecf327cda8bbaee155a8ed7aff51164bb7e387dd40917e97c2e478bca97
file:
batch:
create_procedure_statement:
- keyword: CREATE
- keyword: PROC
- object_reference:
- identifier: '[Reporting]'
- dot: .
- identifier: '[PowerPlan]'
- keyword: AS
- procedure_statement:
statement:
declare_segment:
keyword: DECLARE
parameter: '@DATEFUNCTION'
data_type:
identifier: DATE
comparison_operator: '='
function:
function_name:
function_name_identifier: GETDATE
bracketed:
start_bracket: (
end_bracket: )
begin_end_block:
- keyword: BEGIN
- statement:
select_statement:
select_clause:
keyword: SELECT
select_clause_element:
literal: '1'
- keyword: END