SQL User Defined Function Within Select

madcolor picture madcolor · Dec 12, 2008 · Viewed 310.3k times · Source

I have a user defined function in SQL called getBuisnessDays it takes @startdate and @enddate and returns the number of business days between the two dates. How can I call that function within my select?

Here's what I'd like to do..

SELECT getBusinessDays(a.opendate,a.closedate) 
FROM account a
WHERE ...

Answer

user17670 picture user17670 · Dec 12, 2008

Yes, you can do almost that:

SELECT dbo.GetBusinessDays(a.opendate,a.closedate) as BusinessDays
FROM account a
WHERE...