I want to write a function to return datediff ignoring weekends on SQL Server. Is it allowed to pass interval as an argument on my user defined function, as following? SQL Server is saying "Invalid parameter 1 specified for datediff."
CREATE FUNCTION [dbo].[DATEDIFFWD](@interval varchar(2), @ini datetime, @end datetime)
RETURNS int
AS
BEGIN
DECLARE @output int
SET @output = DATEDIFF(@interval, @ini, @end)
IF (@interval = 'hh') SET @output = @output - (DATEDIFF(WK, @ini, @end) * 48)
IF (@interval = 'dd') SET @output = @output - (DATEDIFF(WK, @ini, @end) * 2)
RETURN @output
END