August 31, 2020 at 3:29 am
Hello guys, have a nice day.
What is better code:
CREATE PROCEDURE SPtest
@kind NVARCHAR(5)
AS
BEGIN
SET NOCOUNT ON;
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
IF @kind = '1'
BEGIN
SELECT * FROM dbo.table1
END
IF @kind = '2'
BEGIN
SELECT * FROM dbo.table2
END
END
Or:
CREATE PROCEDURE SPtest
@kind NVARCHAR(5)
AS
BEGIN
SET NOCOUNT ON;
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
IF @kind = '1'
BEGIN
SELECT * FROM dbo.table1
END
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
IF @kind = '2'
BEGIN
SELECT * FROM dbo.table2
END
END
August 31, 2020 at 6:35 am
I'm tempted to say that none of them are good. If you really have reason to put this exceptional command in a stored procedure, you should add a comment that says why you are taking this gamble, and why it is acceptable.
[font="Times New Roman"]Erland Sommarskog, SQL Server MVP, www.sommarskog.se[/font]
August 31, 2020 at 7:39 am
neither is good - but having the single set statement just makes it easier for you to change your code when time comes your users complain about bad data
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply