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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:36:45+00:00 2026-06-15T02:36:45+00:00

I have a couple SQL Server 2012 queries working but cannot figure out how

  • 0

I have a couple SQL Server 2012 queries working but cannot figure out how to combine them into a single result set. I would like to see [Total Claims] and [Reversed Claims] as adjacent columns in the same result set. Is this possible?

select [Date], DATENAME(weekday, [Date]) as [Day], [Total Claims]
from (Select [Date], count(*) as [Total claims] from ClaimHistoryView group by [Date] )
as CountByDay
order by [Date] desc

select [Date], DATENAME(weekday, [Date]) as [Day], [Reversed Claims]
from (Select [Date], count(*) as [Reversed Claims] from ClaimHistoryView where status = 2 group by [Date] ) as CountByDay
order by [Date] desc
  • 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-15T02:36:46+00:00Added an answer on June 15, 2026 at 2:36 am

    The trick is to combine the two queries using a ‘union all’ with another column indicating where the data comes from and then doing a selective pivot. Hmm. complicated explanation (sorry, german)

    This should do the trick

    select [Date], 
           DATENAME(weekday, [Date]) as [Day], 
           sum(case when Source = 1 then value else 0 end) as [Total Claims],
           sum(case when Source = 2 then value else 0 end) as [Reversed Claims]
    from
    (
      select 
            1 as source, 
            [Date], 
            count(*) as value 
      from  ClaimHistoryView 
      group by [Date]
    union all
      select 
            2 as source,
            [Date],  
            count(*) as value 
      from  ClaimHistoryView 
      where status = 2 
      group by [Date]
    ) as CountByDay 
    Group by [Date]
    order by [Date] desc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a couple of windows service applications that working with sql server. I
I have a SQL server and couple Windows clients and cache of some tables
I have a couple of LINQ to SQL queries that I feel take a
Using SQL SERVER 2005, I have a couple of questions on Replication and referential
We have a couple of mirrored SQL Server databases. My first problem - the
I have a couple of ms sql server (2000) stored procedures encrypted by ex-employee
I have a couple of images in my SQL Server 2008 table of which
I have a couple of projects which reference SQL Server assemblies. With SQL Server
I have a couple of stored procedures on SQL Server 2005 that I've noticed
I have a couple of tables that are joined by GUIDs in SQL Server.

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.