Firstly apologies - I know there are numerous threads on this subject however I can't find an answer to my question.
I have a UDF to work out business days between two dates. I am using SQL Server 2008.
CREATE FUNCTION dbo.fn_CountWeekDays
(
@fromdate Datetime,
@todate Datetime
)
RETURNS TABLE AS RETURN
(
SELECT
(DATEDIFF(dd, @fromdate, @todate) + 1)
-(DATEDIFF(wk, @fromdate, @todate) * 2)
-(CASE WHEN DATENAME(dw, @fromdate) = 'Sunday' THEN 1 ELSE 0 END)
-(CASE WHEN DATENAME(dw, @todate) = 'Saturday' THEN 1 ELSE 0 END)
As NoOfWeekDays
)
I am trying to call it in a select statement along with another table:
select dbo.fn_CountWeekDays(a.date1,a.date2) as workdays
from alex_datetest a
However I am getting the error:
Cannot find either column "dbo" or the user-defined function or aggregate "dbo.fn_CountWeekDays", or the name is ambiguous.
If I drop the dbo. then I get this:
'fn_CountWeekDays' is not a recognized function name.
Does anyone have any ideas why I can't reference this function?
Thanks in advance
Alex