Solved

How to comine like fields in MS SQL

Posted on 2009-05-18
5
179 Views
Last Modified: 2012-05-07
I have the following query from a stored procedure, and I want to combing the ShortDescrption value in the counts by the names listed in the where clause so that it counts all Approved as one count for example, instead of several. How do I do that?
select 
(select Count(1) LoanCount from  @SummaryReportBasic), 
ShortDescription ,
LoanAmount = sum(loanamount),
CountofLoan from @SummaryReportBasic
where shortdescription in ('Approved', 'Approved and awaiting Esign and/Or Certification', 'Certified and Ready for Disbursement','Pending','On Hold','Approved but Cancelled', 'Cancelled/Withdrawn', 'Denied')
Group by shortdescription, CountofLoan
Order by shortdescription

Open in new window

0
Comment
Question by:crosstf
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 57

Assisted Solution

by:Raja Jegan R
Raja Jegan R earned 300 total points
ID: 24412155
Hope this helps:

If I misunderstood your requirement, give the sample result set of the query below and the expected result set to help you better
select 
ShortDescription ,
Count(1) LoanCount, 
LoanAmount = sum(loanamount) 
from @SummaryReportBasic
where shortdescription in ('Approved', 'Approved and awaiting Esign and/Or Certification', 'Certified and Ready for Disbursement','Pending','On Hold','Approved but Cancelled', 'Cancelled/Withdrawn', 'Denied')
Group by shortdescription
Order by shortdescription

Open in new window

0
 

Author Comment

by:crosstf
ID: 24412244
That query provides the following dataset, and I need to combing rows were the shortdescription IS the same. Its lists them separately. So all Approved as one row, all Approve and awaiting, etc.
-------------------------------------------------------------------------------------------------------------- ----------- --
21          Approved                                                                                             10000       1
21          Approved                                                                                             34081       4
21          Approved                                                                                             356423      23
21          Approved and awaiting                                                                        10001       1
21          Approved and awaiting                                                                        11555       2
21          Approved and awaiting                                                                        247156      25
21          Approved and awaiting                                                                        351008      31
21          Approved but Cancelled                                                                       10000       1
21          Cancelled/Withdrawn                                                                           124345      9
21          Cancelled/Withdrawn                                                                           1569556     128
21          Certified and Ready                                                                              16104       1
21          Certified and Ready                                                                              47503       4
21          Certified and Ready                                                                               77621       9
21          Denied                                                                                                   687166      51
21          Pending                                                                                                5990        1
21          Pending                                                
0
 
LVL 57

Assisted Solution

by:Raja Jegan R
Raja Jegan R earned 300 total points
ID: 24412310
What about the result set of the query which I provided
0
 

Accepted Solution

by:
crosstf earned 0 total points
ID: 24412482
This worked. Thank you for your help.
select ShortDescription, sum(CountofLoan) TotalCount, sum(LoanAmount) TotalLoanAmount from @SummaryReportBasic
where ShortDescription in ('Loans Disbursed To Date','Approved and awaiting Esign and/Or Certification','Pending','On Hold','Approved but Cancelled', 'Cancelled/Withdrawn', 'Denied') 
Group by ShortDescription 

Open in new window

0
 

Author Comment

by:crosstf
ID: 24412502
Thank you, was able to obtain the solution.
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Introduction Earlier I wrote an article about the new lookup functions (http://www.experts-exchange.com/A_3433.html) that ship with SQL Server 2008 R2.  In this article I’m going to show you another new feature of SSRS 2008 R2, this time in the vis…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

728 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