Solved

sql server 2008 - union all alternative

Posted on 2013-11-06
3
1,194 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
[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 Comments
 
LVL 66

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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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, …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

734 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