SQL Server generation time range

Source: Internet
Author: User

A similar article was written earlier, which is used for development
If OBJECT_ID (n ' tf_data_timerange ', n ' FN ') is not Nulldrop function Tf_data_timerangegocreate function tf_data_timerange (@startDate varchar (20),--Start date @enddate varchar (20),--End date @datatype INT--Data type 1: Hours 2: Day) returns @temp table ( Int,monitortime varchar (as/********************************--function): Recursive generation time period--author:zhujt--create date:2015-5-28 17:07:11*********************************/beginif @dataType =1 beginwith Temp (orderby,vdate) as ( Select 1 orderby,convert (varchar), @startDate, +) union ALL Select Orderby+1, convert (varchar), DATEADD (hour,1, vdate) from temp where vdate < @endDate) insert into @temp (orderby,monitortime) Select Orderby,vdate from TEM Poption (maxrecursion 0)--exclusion limit value Endelse if @dataType =2begin set @endDate =convert (varchar), @endDate, +); with temp ( orderby,vdate) as (select 1 orderby,convert (varchar), @startDate,) union ALL Select Orderby+1, convert (varchar (10) , DateAdd (Dd,1,vdate), () from temp where Vdate < @endDaTE) insert into @temp (orderby,monitortime) Select Orderby,vdate from Tempoption (maxrecursion 0)--exclusion limit value End Return;end 

SQL Server generation time range

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.