Comments
2 comments
-
Hi @SkipSailors!
The recommendation is to use sp_executesql instead of exec https://documentation.red-gate.com/codeanalysis/best-practice-rules/bp013
However can I just confirm if that wouldn't work in this case? (Apologies as I'm not a SQL developer myself!)
-
hi @SkipSailors - if you have SQL Server 2016 SP1 or onwards you can use the CREATE OR ALTER PROCEDURE statement.
example below:CREATE OR ALTER PROCEDURE dbo.sp_testASSELECT 1;GOEXEC dbo.sp_test;goCREATE OR ALTER PROCEDURE dbo.sp_testASSELECT 2goEXEC dbo.sp_test
Add comment
Please sign in to leave a comment.
So, my pattern is that I have an if statement that checks the sys.objects for the procedure, and it it isn't there, creates a minimal one that the ALTER can use.
SQL Prompt explains to me (BP013) that I should avoid exec('...'). What other ways do I have to create a generic minimal procedure if there is not one present?