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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:45:44+00:00 2026-05-28T05:45:44+00:00

Greeting all. I have a SQL Server 2008 Express database with a table called

  • 0

Greeting all.

I have a SQL Server 2008 Express database with a table called tbl_Sales, similar as following:

Merchant | Sales |  Month
Comp.1      100     201101
Comp.1      200     201102
Comp.2      130     201102
Comp.1      250     201103
Comp.2      130     201103
Comp.3      240     201103
             .
             .
             .
Comp.3      340     201111
Comp.2      240     201112
Comp.3      140     201112

I want to generate the following data in MVC3 chart.

But the chart need all merchants’ data every months else it will conflict.

So is there a way for SQL to do the result as following:

Merchant | Sales |  Month
Comp.1      100     201101
Comp.2        0     201101
Comp.3        0     201101
Comp.1      200     201102
Comp.2      130     201102
Comp.3        0     201102
Comp.1      250     201103
Comp.2      130     201103
Comp.3      240     201103
             .
             .
             .
Comp.3      340     201111
Comp.1        0     201112
Comp.2      240     201112
Comp.3      140     201112

We can have another table tbl_Merchant list out all the Merchant we need as following:

Merchant 
Comp.1
Comp.2
Comp.3
  .
  .
  .
Comp.10

Any suggestion will be welcome.

Thank you very much.

  • 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-28T05:45:44+00:00Added an answer on May 28, 2026 at 5:45 am

    Yes – do a cartesian join of Merchants to Months to be reported (so that you get each month row for every merchant), then left join to your data table – like so:

    select mth.[Month], mct.Merchant, coalesce(s.Sales,0) Sales
    from (select distinct [Month] from tbl_Sales) mth
    cross join Merchant mct
    left join tbl_Sales s 
           on mth.[Month] = s.[Month] and mct.Merchant = s.Merchant
    

    (If tbl_Sales is particularly large, it might be quicker to populate the mth inline view with the necessary range of months from a recursive CTE-generated list of months, rather than selecting the necessary set of months from the Sales data.)

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

Sidebar

Related Questions

Greeting all. I have a SQL 2008 express database, lets name is tbl_Merchant, similar
Greeting all... i have two table and their structure is identical... Table logDetail Date
Greetings, stack overflow In my database, I already have one table, 'contacts' that contains
greeting all i am working on school project and i have a problem with
Greetings All, I have a SQLite database that I'm trying to add a new
Greetings All; I have a desktop java application which gives the following output in
Greetings all, I have a question. On my MOSS 2007 dev box, I created
Greetings all, I have a question. I am trying to build a parametrized query
Greetings to all! This is my first question here on stackoverflow. I have a
Greeting, Is there a live streaming server for silverlight 4 from Microsoft like Flash

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.