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

  • Home
  • SEARCH
  • 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 121191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:55:52+00:00 2026-05-11T03:55:52+00:00

I am trying to do a nice SQL statement inside a stored procedure. I

  • 0

I am trying to do a nice SQL statement inside a stored procedure.

I looked at the issue of seeing the number of days that events happened between two dates. My example is sales orders: for this month, how many days did we have sales orders?

Suppose this setup:

CREATE TABLE  `sandbox`.`orders` (   `year` int,   `month` int,   `day` int,   `desc` varchar(255)  )   INSERT INTO orders (year, month, day, desc)   VALUES (2009,1,1, 'New Years Resolution 1')       ,(2009,1,1, 'Promise lose weight')       ,(2009,1,2, 'Bagel')       ,(2009,1,12, 'Coffee to go') 

For this in-data the result should be 3, since there has been three days with sale. The best solution I found is as below.

However, making a temporary table, counting that then dropping it seemes excess. It ‘should’ be possible in one statement.

Anyone who got a ‘nicer’ solution then me?

/L

SELECT [Year], [Month], [Day] INTO #Some_Days FROM Quarter WHERE Start >= '2009-01-01' AND [End] < '2009-01-16' GROUP BY [Year], [Month], [Day]  SELECT count(*) from #Some_Days 
  • 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. 2026-05-11T03:55:52+00:00Added an answer on May 11, 2026 at 3:55 am

    Apologies if I’m misunderstanding the question, but perhaps you could do something like this, as an option:

    SELECT COUNT(*) FROM     (SELECT DISTINCT(SomeColumn)        FROM MyTable       WHERE Something BETWEEN 100 AND 500       GROUP BY SomeColumn) MyTable 

    … to get around the temp-table creation and disposal?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 227k
  • Answers 227k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There are really two separate parts to this question. What… May 13, 2026 at 1:27 am
  • Editorial Team
    Editorial Team added an answer Build a spatial subdivision structure such as a quadtree or… May 13, 2026 at 1:27 am
  • Editorial Team
    Editorial Team added an answer Get coords of the image (css: top, left) and coords… May 13, 2026 at 1:27 am

Related Questions

Hey all, I'm pulling my hair out on this one. I've checked all my
I know how that question looks, but I'm quite serious. I am trying to
I have a project with a formidable data access layer using LinqtoSQL for just
I am trying to learn Asp.net Mvc so I am trying out this Tutorial.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.