Home Forums SQL Server 7,2000 T-SQL Need to Split a Date Column into 2 solumn as Start Date and End Date RE: Need to Split a Date Column into 2 solumn as Start Date and End Date

  • This can easily be achieved by using NTILE.

    DECLARE @parts INT = 5;

    SELECT

    StartDate= MIN([Date])

    ,EndDate= MAX([Date])

    FROM

    (

    SELECT

    [Date]

    ,Parts = NTILE(@parts) OVER (ORDER BY [DateOfYear])

    FROM [dbo].[myDateTable]

    WHERE [Year] = 2014

    ) tmp

    GROUP BY Parts;

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP