This just scratches the surface on what a function can do for you.
<http://www.sqlshare.com/player.aspx?vid=602>


We do stuff like this as well:
ALTER FUNCTION [dbo].[TimeGapTable](@StartTime datetime, @EndTime
datetime, @GapInMinutes int)
RETURNS @TimeGaps TABLE
(
    -- columns returned by the function
    GapDate datetime NOT NULL,
    Time1 datetime  NULL,
    Time2 datetime  NULL
)
AS
-- body of the function
BEGIN
        declare @date datetime, @time1 datetime, @time2 datetime, @end datetime

        set @date = convert(varchar(20),@StartTime,101)

        set @time1 = @StartTime
        set @time2 = @StartTime

        while @time1 < @EndTime
        BEGIN
        insert into @TimeGaps ([GapDate],Time1, Time2)
        select @date, @time1, @time2
        set @time1 = dateadd(n,@GapInMinutes,@time1)
        set @time2 = dateadd(n,@GapInMinutes,@time1)
        END

   RETURN
END


-- 
Stephen Russell

Unified Health Services
60 Germantown Court
Suite 220
Cordova, TN 38018

Telephone: 888.510.2667

901.246-0159 cell

_______________________________________________
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: 
http://leafe.com/archives/byMID/profox/CAJidMYK9qp8e=uwtxy5-ganertuaxg2epvuo---lrnsy+ca...@mail.gmail.com
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to