Solved

sql server 2008 - union all alternative

Posted on 2013-11-06
3
1,158 Views
Last Modified: 2013-11-06
I have a table with an amount field and a description field. The description field contains either 'Electric', 'Water' , Sewer, StormWater, Telecom, Fire, or Sanitation.  
I want to create a summary record that will have
LocationId,
ServiceAddr,
and a summed amt for each description (7 different fields. I can do this using Union all, and it works fine. I am wondering if there is a better way. I am attaching my code(partial)that works.UnionAll.txt
0
Comment
Question by:qbjgqbjg
3 Comments
 
LVL 65

Expert Comment

by:Jim Horn
ID: 39627812
At the risk of a knee-jerk 'what the heck are you trying to do here?', please provide us a data mockup of your source, and another one of your desired result set.

Guessing this will be pretty easy.
0
 
LVL 26

Accepted Solution

by:
Shaun Kline earned 500 total points
ID: 39627906
Based on the attached file, it appears you want to PIVOT your data. The following link on Microsoft's website provides documentation for this command (SQL Server 2005 and up):

http://technet.microsoft.com/en-us/library/ms177410(v=sql.105).aspx

Another example can be found at the link below which also includes an example for pivoting data on SQL Server 2000:

http://archive.msdn.microsoft.com/SQLExamples/Wiki/View.aspx?title=PIVOTData
0
 

Author Closing Comment

by:qbjgqbjg
ID: 39627984
Thanks the pivot example is exactly what I am trying to accomplish.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Audit has been really one of the more interesting, most useful, yet difficult to maintain topics in the history of SQL Server. In earlier versions of SQL people had very few options for auditing in SQL Server. It typically meant using SQL Trace …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

733 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