I need to create a stored procedure that needs to return a count of some records. I’m using .Net to read the result.
I can use an OUTPUT
parameter to return the value or I could do a select count(*)
in the stored procedure and use a SqlCommand.ExecuteScalar to read it.
What is better and why?
Advertisement
Answer
Check out this MSDN article: Performance Comparison: Data Access Techniques
The article shows in the performance test for GetOrderStatus
that the performance between OUTPUT parameter and ExecuteScaler is the same for retreiving a single value, but ExecuteScalar requires less code.
Here are some other interesting thoughts about not going for the OUTPUT parameter:
What’s wrong with output parameters. I like the thought of Output params break the fundamental idea of a function
in that post.