Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6663725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:31:50+00:00 2026-05-26T02:31:50+00:00

Need help, struggling to do this please Got the following fields in table Package_Name

  • 0

Need help, struggling to do this please

Got the following fields in table

Package_Name
Package_StartTime
Package_Endtime

What I require is:

Based on data range give me how much time each package took time to execute

like

Package Name - 21 Sept    22 Sept    23 Sept
ABC             3 mins     4 mins      2 mins

This way I want to see the execution time pattern of the packages.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:31:51+00:00Added an answer on May 26, 2026 at 2:31 am

    For every package, this query will calculate execution time in minutes for every day between StartTime and EndTime.

    Solution:

    CREATE TABLE dbo.Package
    (
        Name NVARCHAR(10) PRIMARY KEY
        ,StartTime DATETIME NOT NULL
        ,EndTime DATETIME NOT NULL
    );
    
    INSERT  dbo.Package 
    SELECT  'A', '2011-01-01T00:02:00', '2011-01-01T00:05:00'
    UNION ALL
    SELECT  'B', '2011-01-01T23:50:00', '2011-01-02T00:04:00'
    UNION ALL
    SELECT  'C', '2011-01-01T23:50:00', '2011-01-01T23:59:00'
    UNION ALL
    SELECT  'D', '2011-01-02T22:10:00', '2011-01-05T01:00:00';
    
    WITH PivotSource
    AS
    (
        SELECT  a.Name
                ,CONVERT(VARCHAR(25),b.DayStartTime,112) [Day]
                ,DATEDIFF(MINUTE,b.DayStartTime,b.DayEndTime) DayMinutes
        FROM    dbo.Package a
        CROSS APPLY
        (
            SELECT  v.number
                    ,CONVERT(VARCHAR(25),DATEADD(DAY,v.number,a.StartTime),112) IntermediateTime
                    ,CASE 
                        WHEN v.number=0 THEN a.StartTime
                        ELSE CONVERT(VARCHAR(25),DATEADD(DAY,v.number,a.StartTime),112)
                    END DayStartTime
                    ,CASE 
                        WHEN CONVERT(VARCHAR(25),a.EndTime,112)=CONVERT(VARCHAR(25),DATEADD(DAY,v.number,a.StartTime),112) THEN a.EndTime
                        ELSE CONVERT(VARCHAR(25),DATEADD(DAY,v.number,a.StartTime),112)+' 23:59:59.999'
                    END DayEndTime          
            FROM    master.dbo.spt_values v
            WHERE   v.type = 'P'
            AND     v.number <= DATEDIFF(DAY,a.StartTime,a.EndTime)
        ) b
    )
    SELECT  pvt.*
    FROM    PivotSource cte
    PIVOT( SUM(cte.DayMinutes) FOR cte.[Day] IN ([20110101],[20110102],[20110103],[20110104],[20110105]) ) pvt
    
    DROP TABLE dbo.Package;
    

    Results:

    Name       20110101    20110102    20110103    20110104    20110105
    ---------- ----------- ----------- ----------- ----------- -----------
    A          3           NULL        NULL        NULL        NULL
    B          10          4           NULL        NULL        NULL
    C          9           NULL        NULL        NULL        NULL
    D          NULL        110         1440        1440        60
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need help writing a script downloads data from google insight using c# this is
I need help on this following aspx code aspx Code: <asp:Label ID =lblName runat
Got following fields in table: Run Date : 2011-09-25 00:00:00.000 Run Time : 05:00:00
I need help with a SQL that will convert this table: =================== | Id
I need help with this route map routes.MapRoute(Blog_Archive, Blog/Archive/{year}/{month}/{day}, new { controller = Blog,
i need help with disk_total_space function.. i have this on my code <?php $sql=select
I've been struggling with this for a while now so hopefully someone can help
May I ask for your help with the following please ? I am trying
Struggling with this tournament fixtures algorithm. The code is working perfectly but I need
I've been struggling with this issue for a while now. Maybe you can help.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.