[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Is there someway I can return this in a single query as a single dataset?

Posted on 2013-05-13
13
Medium Priority
?
245 Views
Last Modified: 2013-05-13
Select count(ColumnA),ColumnB,ColumnC
From Table A
Where dateA > '01/01/2012'

AND

Select count(ColumnA),ColumnB,ColumnC    
From TableA
0
Comment
Question by:rhservan
  • 5
  • 4
  • 4
13 Comments
 
LVL 25

Expert Comment

by:Ron Malmstead
ID: 39162128
Select count(ColumnA),ColumnB,ColumnC
From TableA A
Where dateA > '01/01/2012'

UNION ALL

Select count(ColumnA),ColumnB,ColumnC    
From TableA  B
0
 

Author Comment

by:rhservan
ID: 39162177
The count column in each query needs to remain as separate count columns.  Of course the difference being is one has the date filter the other does not.
0
 
LVL 31

Expert Comment

by:hnasr
ID: 39162252
Modifying your query:

Select count(ColumnA),ColumnB,ColumnC
From Table A
Where dateA > '01/01/2012'
GROUP BY ColumnB, ColumnC
Union
Select count(ColumnA),ColumnB,ColumnC    
From TableA
GROUP BY ColumnB, ColumnC
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 31

Expert Comment

by:hnasr
ID: 39162256
"The count column in each query needs to remain as separate count columns. "
What do you mean? Give example.
0
 

Author Comment

by:rhservan
ID: 39162280
What I really need is this:

ColumnA1  ColumnA2   ColumnB    ColumnC

I need to maintain the two different count columns.  If I use UNION or UNION ALL - won't the counts just be merged?
0
 
LVL 25

Expert Comment

by:Ron Malmstead
ID: 39162297
Try this..
Let me know if this is what you're after.

Select count(ColumnA) As Table1Count,'' as Table2Count,ColumnB,ColumnC
From TableA A
Where dateA > '01/01/2012'

UNION ALL

Select '' as Table1Count, count(ColumnA) as Table2Count,ColumnB,ColumnC    
From TableA  B
0
 
LVL 25

Accepted Solution

by:
Ron Malmstead earned 2000 total points
ID: 39162309
Or...

Select count(ColumnA),TotalCount=(SELECT Count(ColumnA) FROM TableA),ColumnB,ColumnC
From TableA A
Where dateA > '01/01/2012'
0
 

Author Comment

by:rhservan
ID: 39162327
ColumnA1&A2 are the same column with just the date filter difference.
I need ColumnA1 count based on the date filter
I need ColumnA2 count based on without date filter

ColumnA1   ColumnA2    
   500              10000
0
 
LVL 25

Expert Comment

by:Ron Malmstead
ID: 39162337
right,...try my last suggestion.
That should work.

Select count(ColumnA) as ColumnA1,ColumnA2=(SELECT Count(ColumnA) FROM TableA),ColumnB,ColumnC
From TableA A
Where dateA > '01/01/2012'
0
 
LVL 31

Expert Comment

by:hnasr
ID: 39162522
This will be a repeating column values, right?
List few records and the required output.

Select (Select count(ColumnA),ColumnB,ColumnC
From Table A Where dateA > '01/01/2012') As ColumnA ,
                   (Select count(ColumnA),ColumnB,ColumnC
From Table A) As ColumnA2,
                   ColumnB,ColumnC
From Table A
0
 

Author Comment

by:rhservan
ID: 39162533
You are correct in that it gives the Total count for ColumnA2, but It doesn't breakout by name as in ColumnA1, see below:

ColumnB      ColumnA1        ColumnA2
Name1                 6                       540
Name2                 16                     540
Name3                 3                       540
Name4                 14                     540
Name5                  1                      540

So ColumnA2 doesn't appear to be using the main query portion for other things.
0
 
LVL 31

Expert Comment

by:hnasr
ID: 39162553
What is the raw data

ColumnA ColumnB
----               Name1
----                ----
To produce the above shown result?
0
 

Author Comment

by:rhservan
ID: 39162600
Raw Data
ColumnB - Full Name
ColumnA1 - interaction dates  
ColumnA2 - interaction dates
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question