User Defined SQL Function Inside Selection

I have a custom function in SQL called getBuisnessDays, it takes @startdate and @enddate and returns the number of working days between two dates. How can I call this function inside my choice?

Here is what I would like to do.

SELECT getBusinessDays(a.opendate,a.closedate) FROM account a WHERE ... 
+42
sql sql-server select user-defined-functions
Dec 12 '08 at 19:16
source share
3 answers

Yes, you can do almost this:

 SELECT dbo.GetBusinessDays(a.opendate,a.closedate) as BusinessDays FROM account a WHERE... 
+74
Dec 12 '08 at 19:22
source share

If this is a table-value function (returns a table) you simply join it as a table

this function generates one column table with all the values ​​from a comma-supplied list

 SELECT * FROM dbo.udf_generate_inlist_to_table('1,2,3,4') 
+5
Dec 12 '08 at 19:29
source share

Use a scalar-valued UDF, not a table value, then you can use it in SELECT as you wish.

+4
Dec 12 '08 at 19:25
source share



All Articles