Store Procedure, stored procedures. It's something that someone else has written. I habitually see what others have written before I begin to see what I have to write. So let's talk about the difference between it and the UDF.
In the LINQ to SQL Advanced Series (d) User Define function article, we mentioned the difference between the two. For example, store procedure support multiple rowset, and UDF is not. They also have some other differences. Store procedure can only return an integer, and the UDF may be other types, such as Char, which, except for individual types, such as the imager type, are not allowed to be the return type of the UDF. The Store procedure supports out parameter and the UDF does not.
1, Singleresultset
Let's take a look at this sprocs first.
CREATE PROCEDURE [dbo].[Customers By City]
-- Add the parameters for the stored procedure here
(@param1 NVARCHAR(20))
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SELECT CustomerID, ContactName, CompanyName, City from Customers as c where c.City=@param1
END
Its generated code is as follows.
[Function(Name="dbo.[Customers By City]")]
public ISingleResult<Customers_By_CityResult> Customers_By_City([Parameter (DbType="NVarChar(20)")] string param1)
{
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo) (MethodInfo.GetCurrentMethod())), param1);
return ((ISingleResult<Customers_By_CityResult>)(result.ReturnValue));
}
Here Customers_by_cityresult is the sprocs of this kind of innuendo. But you can adjust it in or designer. As pictured,