Solved

sql server 2008 - union all alternative

Posted on 2013-11-06
3
1,138 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
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.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

829 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