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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:00:11+00:00 2026-06-13T03:00:11+00:00

I want to show all dates between two dates when there is any date

  • 0

I want to show all dates between two dates when there is any date data missing then its should show zero in val column .

declare @temp table (
id int identity(1,1) not null,
CDate smalldatetime ,
val int
)

INSERT STATEMENT FOR DATA TO CHECK

insert into @temp select '10/2/2012',1
insert into @temp select '10/3/2012',1
insert into @temp select '10/5/2012',1
insert into @temp select '10/7/2012',2
insert into @temp select '10/9/2012',2
insert into @temp select '10/10/2012',2
insert into @temp select '10/13/2012',2
insert into @temp select '10/15/2012',2

Retrieve records between first day of month and today

select * from @temp where CDate between '10/01/2012' AND '10/15/2012'

As i run this query its show me all data between these two dates but i want to also include missing dates with val=0

SQL FIDDLE WITH SAMPLE DATA

  • 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-13T03:00:13+00:00Added an answer on June 13, 2026 at 3:00 am
    ;with d(date) as (
      select cast('10/01/2012' as datetime)
      union all
      select date+1
      from d
      where date < '10/15/2012'
      )
    select t.ID, d.date CDate, isnull(t.val, 0) val
    from d
    left join temp t
           on t.CDate = d.date
    order by d.date
    OPTION (MAXRECURSION 0) -- use this if your dates are >99 days apart
    

    You need to make up the dates, so I’ve use a recursive common table expression here.
    SQL Fiddle

    MAXRECURSION number

    Specifies the maximum number of recursions allowed for this query. number is a nonnegative
    integer between 0 and 32767. When 0 is specified, no limit is applied. If this option is
    not specified, the default limit for the server is 100.

    When the specified or default number for MAXRECURSION limit is reached during query
    execution, the query is ended and an error is returned.

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

Sidebar

Related Questions

I want to show all PDF filenames that has 33 in any position. sample
How to list all available LookAndFeel themes? I want to show then in a
I want to compare between two dates. From both the dates, I am fetching
Good Day all, I want to use datepicker to show the user particular dates
There are many question posted about getting the difference between two dates in Oracle.
I want to show all users present in a database. I want to place
i want to show all the vehicle maintenance history when user click on the
Fist of all I want to show you my code/storyboard: This is my storyboard:
all I want to show hide some ids using jQuery. My html code is
Hi all I am developing an app.I want to show a table view with

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.