Call a function in sql code example
Example 1: call function in query sql server
SELECT dbo.GetBusinessDays(a.opendate,a.closedate) as BusinessDays
FROM account a
WHERE...
Example 2: functions with parameters SQL
DECLARE
@OrderID int = NULL,
@OrderType int = 1,
@Qty int = 2,
@ServiceSpeed int = 3;
INSERT INTO OrdersTest (OrderType, Qty, ServiceSpeed)
VALUES (@OrderType, @Qty, @ServiceSpeed);
EXEC @OrderID = dbo.GetOrderID
@OrderType = @OrderType,
@Qty = @Qty,
@ServiceSpeed = @ServiceSpeed;
SELECT @OrderID 'Using EXEC Syntax';
Example 3: functions with parameters SQL
EXEC @OrderID = dbo.GetOrderID
@OrderType = @OrderType,
@ServiceSpeed = @Qty,
@Qty = @ServiceSpeed;