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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:26:28+00:00 2026-05-28T00:26:28+00:00

I have, after some help ( MSChart – Forcing a line chart to draw

  • 0

I have, after some help (MSChart – Forcing a line chart to draw from the Origin), managed to put together the following MSSQL query for use in a line chart.

WITH AllDays
AS
(
    SELECT CAST('20120101' as datetime) AS days
    UNION ALL
    SELECT DATEADD(dd, 1, days)
    FROM AllDays
    WHERE DATEADD(dd, 1, days) < cast('20120201' as datetime)
)
SELECT
    MIN(ad.days) AS Date,
    ISNULL((SELECT SUM(value) FROM jobs WHERE dateinvoiced >= CAST('20120101'
    as datetime) AND dateinvoiced <= ad.days)/100,0) AS Value
FROM AllDays AS ad
LEFT JOIN jobs AS j
ON( ad.days = j.dateinvoiced )

GROUP BY ad.days

However, I have a problem. This query returns something like the below:

Date                    | Value

2012-01-01 00:00:00.000 |     0 
2012-01-02 00:00:00.000 |     0
2012-01-03 00:00:00.000 |  1234
2012-01-04 00:00:00.000 |  1234
2012-01-05 00:00:00.000 |  1234
2012-01-06 00:00:00.000 | 57312
2012-01-07 00:00:00.000 | 57312
2012-01-08 00:00:00.000 | 90812

This means that I get a reading for every single day, whereas in fact I only require one row for each distinct Value. I want the first time it appears, in every case, so for the above example I would want my query to return:

Date                    | Value

2012-01-01 00:00:00.000 |     0
2012-01-03 00:00:00.000 |  1234
2012-01-06 00:00:00.000 | 57312
2012-01-08 00:00:00.000 | 90812

I’ve looked through several questions that seem to be based on a similar premise, but all of the responses were very tailored to the specific situation (some even use LIKE to pick out requested results), and didn’t seem to suit this. They also, of course, would be difficult to fit into the query I already have.

Any ideas? Thanks in advance.

Edit: sorry for dodgy tables, my first attempt was much worse.

  • 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-28T00:26:28+00:00Added an answer on May 28, 2026 at 12:26 am

    Try this. You’ve done the hard part already. You just need to group on Value and get the first (i.e. MIN) Date associated with it:

    WITH AllDays AS (
        SELECT CAST('20120101' as datetime) AS days
        UNION ALL
        SELECT DATEADD(dd, 1, days)
        FROM AllDays
        WHERE DATEADD(dd, 1, days) < cast('20120201' as datetime)
    ), V AS (
      SELECT
        MIN(ad.days) AS Date,
        ISNULL((SELECT SUM(value) FROM jobs WHERE dateinvoiced >= CAST('20120101'
        as datetime) AND dateinvoiced <= ad.days)/100,0) AS Value
      FROM AllDays AS ad
      LEFT JOIN jobs AS j ON (ad.days = j.dateinvoiced)
      GROUP BY ad.days
    )
    SELECT MIN(Date) Date, Value
    FROM V
    GROUP BY Value;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I put together a download script after some wonderful help from stack overflow the
Hi guys I was hoping from some help here, please. I have a INSERT
I'd like some help from the community, if possible. We have a project at
Hi JQuery Masters i need some help from you, i have some div's <div
I’m after some C# code that will have the following methods that will return
After some reading and R&D, I have came to conclusion that ? Forms in
i have philosophised about the purpose of stack a little bit and after some
I have a vs.net project, and after some refactoring, have modified the name of
I have a pretty beefy development machine and three monitors, so after some intense
I have a class that after it does some stuff, sends a JMS message.

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.