Skip to content

Update switching from LEAST() to CASE for NBRecordsEligible#506

Open
VBD-BYoung wants to merge 1 commit intomicrosoft:masterfrom
VBD-BYoung:master
Open

Update switching from LEAST() to CASE for NBRecordsEligible#506
VBD-BYoung wants to merge 1 commit intomicrosoft:masterfrom
VBD-BYoung:master

Conversation

@VBD-BYoung
Copy link

This change replaces the use of the LEAST() function inside the RemoveOrphansOnTablesWithoutDateTime stored procedure with a SQL Server–compliant CASE expression.

Recent versions of SqlPackage/DacFx (v162+) now perform strict validation of stored procedure bodies during BACPAC imports. As part of that validation, the procedure is parsed and compiled using SQL Server’s T‑SQL rules. Because SQL Server does not support the LEAST() function, the BACPAC import fails with:

'LEAST' is not a recognized built-in function name.
SQL72014 / SQL72045

Older SqlPackage versions did not validate SP bodies at this level, which is why this had not surfaced previously.
To restore compatibility, the call to LEAST(@NBRecordsEligible, @batchsize) has been replaced with the equivalent conditional expression:

SQLSELECT @NBRecordsEligible =
CASE WHEN @NBRecordsEligible < @BatchSize
THEN @NBRecordsEligible
ELSE @BatchSize
END;

This maintains identical behavior but ensures SQL Server and SqlPackage accept the procedure during deployment.
No functional or behavioral changes beyond this fix. This update resolves the BACPAC import failure and aligns the stored procedure with T‑SQL standards.

@VBD-BYoung VBD-BYoung changed the title Update switching from LEAST() to CASE for NBRRecordsEligible Update switching from LEAST() to CASE for NBRecordsEligible Feb 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant