函数通常有一个输出和可选的输入。输出可以用作另一个函数(SQL服务器内置的,如DATEDIFF、LEN等)的输入,也可以用作SQL查询的谓词,例如SELECT a, b, dbo.MyFunction(c) FROM table或SELECT a, b, c FROM table WHERE a = dbo.MyFunc(c)。
SELECT Name, dbo.Functionname('Parameter1') FROM sysObjects
For simple reusable select operations, functions can simplify code.Just be wary of using JOIN clauses in your functions. If yourfunction has a JOIN clause and you call it from another selectstatement that returns multiple results, that function call will JOINthose tables together for each line returned in the result set. Sothough they can be helpful in simplifying some logic, they can also be aperformance bottleneck if they're not used properly.