带表的SQL Server标量函数

[英]SQL Server scalar function with table


I have a user defined function like this:

我有一个用户定义的函数,如下所示:

CREATE FUNCTION getMinutesWork
(
    @startT datetime,
    @endT datetime
)
RETURNS int
As
Begin
    bla bla
    bla bla
RETURN @totalMinute
End

It calculates total minutes between two dates. I want to use it with a table like this:

它计算两个日期之间的总分钟数。我想用这样的表来使用它:

WorkerID |LastName| FirstName  |  StartDate          | EndDate
   1     |   JOHN |    SNOW    |1979-12-26 02:47:00  | 1999-02-16 12:44:00
   2     |  ...   |   ...      |   .... .            |    .....

StartDate and EndDate are inputs. But i couldnt figure out how ill turn my function table valued one

StartDate和EndDate是输入。但我无法弄清楚我的功能表如何变得有价值

1 个解决方案

#1


4  

Just call your function in the select:

只需在选择中调用您的函数:

select t.*,
       dbo.getMinutesWork(StartDate, EndDate)
from table t;

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2015/07/28/149830165d9bc7d192373c08593f3448.html



 
© 2014-2018 ITdaan.com 粤ICP备14056181号