dnlnln / generate-sql-merge

Generate SQL MERGE statements with Table data
MIT License
337 stars 151 forks source link

Using '@include_rowsaffected = 0' causes error "A MERGE statement must be terminated by a semi-colon (;)" #85

Closed InsolvencyCrispy closed 2 years ago

InsolvencyCrispy commented 2 years ago

When calling the sproc using @include_rowsaffected = 0 results in an error:

Msg 10713, Level 15, State 1, Line 1
A MERGE statement must be terminated by a semi-colon (;).

For example:

EXEC dbo.sp_generate_merge @include_use_db = 0, @results_to_text = 1, @batch_separator = null, @nologo = 1, @include_rowsaffected = 0, @table_name = 'Printer'

Suggest removing the ';' from line 835 and adding to line 837. i.e.

IF @delete_if_not_matched=1 
BEGIN
 SET @output += @b + 'WHEN NOT MATCHED BY SOURCE THEN '
 SET @output += @b + ' DELETE'
END
IF @include_rowsaffected = 1
BEGIN
 SET @output += @b + 'OUTPUT $action INTO @mergeOutput'
END
SET @output += @b + ';'
dnlnln commented 2 years ago

Thanks for providing that detail, I'll look at getting that fixed asap