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 8211467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:26:07+00:00 2026-06-07T10:26:07+00:00

I am currently working on a query that will be used in junction with

  • 0

I am currently working on a query that will be used in junction with share-point to run reports. I have a query that I know will work with Oracle, but the company I am working for is running SQL Server 2005.

What the report will do is give the person the ability to select any date and time, and give the count for that specific operation. The problem is that there are large gaps in the time stamps (because it takes a little while for the product to get to the next operation). The date type is varchar, so i used substrings to parse out the year, month, day, and time. I have sample data available.

The people looking at the reports want the ability to say at this time and day how many units went through this operation.

I know this is is confusing, let me know if you need any clarification.

Here is the oracle syntax

SELECT T3.PAYMENT_DATE, T3."Hr", T3."Min", 
       (SELECT COUNT(*) 
        FROM INVOICE_ARCHIVE T4 
        WHERE TO_NUMBER(TO_CHAR(T4.PAYMENT_DATE, 'MM')) <= T3."Hr" 
        AND TO_NUMBER(TO_CHAR(T4.PAYMENT_DATE, 'DD')) <= T3."Min") AS "NUM"
FROM(SELECT T1.PAYMENT_DATE, T2."Hr", T2."Min"
     FROM (SELECT (FLOOR((LEVEL + 359)/60)) AS "Hr", 
                  MOD((LEVEL + 359), 60) AS "Min"
           FROM dual CONNECT BY LEVEL <= 961) T2, INVOICE_ARCHIVE T1
     ORDER BY T1.PAYMENT_DATE, T2."Hr", T2."Min") T3
  • 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-06-07T10:26:10+00:00Added an answer on June 7, 2026 at 10:26 am

    The answer to your question is the datepart() function in SQL Server. This will allow you to extract minutes and hours from dates.

    The harder part is the “connect by level” portion. How is this being used? You might need to use recursive CTEs to handle this.

    With the little hint from spencer, the following may suffice for your query:

    SELECT T3.PAYMENT_DATE, T3."Hr", T3."Min",
           (SELECT COUNT(*)
            FROM INVOICE_ARCHIVE T4
            WHERE datepart(month, T4.PAYMENT_DATE) <= T3."Hr" AND
                  datepart(day, T4.PAYMENT_DATE, 'DD') <= T3."Min"
           ) AS "NUM"
    FROM (SELECT T1.PAYMENT_DATE, T2."Hr", T2."Min"
          FROM (SELECT top 961 (FLOOR((LEVEL + 359)/60)) AS "Hr",
                        MOD((LEVEL + 359), 60) AS "Min"
                FROM (select top 961 row_number() over (order by (select NULL)) as level
                      from invoice_archive
                     ) t
               ) T2 cross join
               INVOICE_ARCHIVE T1
         ) T3
     ORDER BY T3.PAYMENT_DATE, T3."Hr", T3."Min"
    

    I made the following changes:

    1. Changed the date arithmetic to use datepart() instead of to_char() .
    2. Replaced the method for getting a list of numbers, by using row_number() instead of connect by level
    3. Made the cross join explicit
    4. Moved the order by to the outer query, since neither SQL Server nor Oracle guarantee the results of an order by in a subquery (and SQL Server does not allow it unless you have a “TOP” query)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently working with a query in in MSSQL that looks like: SELECT
I'm currently working on a search box for my site that will hopefully use
I'm currently working on a daemon that will be doing A LOT of different
Currently working with Oracle, but will also need a solution for MS SQL. I
I have an ecommerce store that I am currently working on and there are
I am currently working on a project that will store specific financial information about
I have a project that I'm currently working on but it currently only supports
I have a good LINQ query that is working well, it returns a result
I have an API server that I am working on it currently accepts requests
Currently all working with my jquery $.post actions, successful connections, query and json_encode return

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.