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 ...
User-defined functions can't call a stored procedure, but can call an extended stored procedure. User-defined functions can't make use of dynamic SQL or temp tables. Table variables are allowed. SET statements aren't allowed in a user-defined function.
Functions can be used anywhere in SQL, like AVG, COUNT, SUM, MIN, DATE and so on with select statements. Functions compile every time. Functions must return a value or result. Functions only work with input parameters.
When calling a function from a SELECT statement, that function can only perform DML (insert, update, delete) statements if it is defined as an AUTONOMOUS_TRANSACTION. 2. You should avoid using RESULT_CACHE with temporary tables. The PL/SQL documentation even presents this as a restriction.
Yes, you can do almost that:
SELECT dbo.GetBusinessDays(a.opendate,a.closedate) as BusinessDays FROM account a WHERE...
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')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With