calcuku
calcuku

Reputation: 67

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

Upvotes: 0

Views: 53

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269603

Just call your function in the select:

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

Upvotes: 4

Related Questions