Solved

sql server query grouping

Posted on 2014-03-12
5
114 Views
Last Modified: 2014-03-18
I have a query that is returning the following data.  

Broward County     07DB-3V-11-16-01-Z 08   596000531    Buyouts    Null          Null
Broward County     07DB-3V-11-16-01-Z 08   596000531    Null          Null          Buyouts

I would like to group it up to just show one line that looks like :

Broward County     07DB-3V-11-16-01-Z 08   596000531    Buyouts     Null     Buyouts

Thanks in advance.
0
Comment
Question by:Paulconsulting
  • 3
5 Comments
 
LVL 7

Expert Comment

by:Kishan Zunjare
ID: 39925592
Here you can use Group By clause in SQL to combine result, you can apply group by on selected columns
0
 

Author Comment

by:Paulconsulting
ID: 39926221
Grouping doesn't work for me in this scenario, at least not that I can tell.  Do you have a query in mind?
0
 

Accepted Solution

by:
Paulconsulting earned 0 total points
ID: 39926311
I resolved it, I inserted the results into a Temp table then joined on itself.
0
 
LVL 69

Expert Comment

by:Scott Pletcher
ID: 39927814
SELECT name, id1, id2, MAX(buyout1) AS buyout1, MAX(buyout2) AS buyout2, MAX(buyout3)  AS buyout3
FROM ...
GROUP BY name, id1, id2


Corresponds to sample data like this:
name = Broward County
id1 = 07DB-3V-11-16-01-Z 08
id2 = 596000531
buyout1 = Buyouts
buyout2 = Null
buyout3 = Null
...
buyout1 = Null
buyout2 = Null
buyout3 = Buyouts
0
 

Author Closing Comment

by:Paulconsulting
ID: 39936368
I resolved it, I inserted the results into a Temp table then joined on itself.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

776 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