SQL User Defined Function Within Select

2019-02-11 09:35发布

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 ...

3条回答
混吃等死
2楼-- · 2019-02-11 10:20

Yes, you can do almost that:

SELECT dbo.GetBusinessDays(a.opendate,a.closedate) as BusinessDays
FROM account a
WHERE...
查看更多
Juvenile、少年°
3楼-- · 2019-02-11 10:21

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

查看更多
4楼-- · 2019-02-11 10:30

If it's a table-value function (returns a table set) you simply join it as a Table

this function generates one column table with all the values from passed comma-separated list

SELECT * FROM dbo.udf_generate_inlist_to_table('1,2,3,4')
查看更多
登录 后发表回答