0

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

4
  • 1
    I'm not following... what is your question? Are you wanting to know how to pass in the values from your table? Commented Jul 28, 2015 at 13:41
  • @siyual Yes. I want to use this function for 3-5k people and see each total minutes on a table. Commented Jul 28, 2015 at 13:43
  • 1
    I think you are confusing a table valued function, with calling a scalar function using values from a table. As far as I can tell your query would be ---- SELECT t.WorkerID, t.LastName, t.Firstname, t.StartDate, t.EndDate, MinutesWork = getMinutesWork(t.StartDate, t.EndDate) FROM YourTable AS t Commented Jul 28, 2015 at 13:45
  • 1
    Performance wise you would be better off if you can use a inline table valued function instead of a scalar function. Commented Jul 28, 2015 at 14:09

1 Answer 1

4

Just call your function in the select:

select t.*,
       dbo.getMinutesWork(StartDate, EndDate)
from table t;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.