Wednesday, October 17, 2007

Sample SQL Funcion and how its calling

//FUNCTION

ALTER FUNCTION [dbo].[ufCheckProductionOrderCreated]
(
@Sales_Order_Id int
)
RETURNS int
AS
BEGIN
DECLARE @cReturnValue INT
SELECT @cReturnValue= count(Id) from ProductionOrder where Sales_Order_Id=@Sales_Order_Id
RETURN @cReturnValue
END


//Calling the Function


SO.ShipAddressState,
SO.ShipAddressPostalCode,
SO.ShipAddressCountry,
C.Customer_Name,dbo.ufCheckProductionOrderCreated(SO.Sales_Order_No) as IsProdOrderCreated
FROM SalesOrder SO, Customers C
WHERE
C.CustomerID=SO.Customer_No

END

No comments: