Ignoring ORM / NHibernate etc. Consider the general requirement of transmitting a unique identifier and returning data from one row (if an ID is found). Two ways to do this is to return a set of records or use the output parameters. The saved proc will be called from .NET C # code - therefore, from this point of view, setting / reading additional parameters using ExecuteNonQuery is required, while the other requires ExecuteScalar and access / reading DataReader.
Are there any real advantages over using one and the other?
CREATE PROC GetUserByRecordSet @UserID UniqueIdentifier AS BEGIN SELECT ID, Name, EmailAddress FROM [User] WHERE id = @UserID END GO CREATE PROC GetUserByOutputParams @UserID UniqueIdentifier, @Name NVARCHAR(255) OUTPUT, @EmailAddress NVARCHAR(500) OUTPUT AS BEGIN SELECT @Name =Name, @EmailAddress = EmailAddress FROM [User] WHERE id = @UserID END GO
source share