Solved

sql server 2008 - union all alternative

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now