Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to comine like fields in MS SQL

Posted on 2009-05-18
5
Medium Priority
?
183 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 1200 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 1200 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

721 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