SQL User Defined Function Within Select

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

  • SQL Server - Is it possible to find the size actually used in an MDF or LDF file
  • Linq to Entities: Parameterised Raw Sql query?
  • primary key duplicate record bypass to next insert
  • SQL Server 2008 Update Trigger
  • Troubleshooting memory problems due to AUTO SHRINK?
  • DB restoration issue
  • SELECT getBusinessDays(a.opendate,a.closedate) 
    FROM account a
    WHERE ...
    

    3 Solutions collect form web for “SQL User Defined Function Within Select”

    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')
    

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

    MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.