Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1274
  • Last Modified:

sql server 2008 - union all alternative

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
qbjgqbjg
Asked:
qbjgqbjg
1 Solution
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
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
 
Shaun KlineLead Software EngineerCommented:
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
 
qbjgqbjgConsultantAuthor Commented:
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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now