473,386 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Pivot data - with dynamic headers

I'm in the process of writing a stored procedure to read a bunch of data, and then pivot it around to import into a report.

At this point, the data is in a temporary table such as this:

DECLARE @unit_category_table table
(
unit_number varchar(50),
category varchar(50),
sort_order int,
TotalQty float
)

In this case, the "category" column is the actual name of the category, and I need a grid where the rows are the units, and the columns are each (and every) unique value of "category". The data itself is the sum of the TotalQty column.

At times, here may be only 5 columns, and 15 at others.

And, to complicate matters further, I have a "sort_order" column to determine in what order those columns should go (1=first, 2=second, etc., and 0=omit column entirely).


But I'm having very little luck figuring out how to pivot that data around as I want.


How do I do what I'm asking?


Thanks!


P.S. For what it's worth, we're running MS SQL 2005.
May 1 '07 #1
0 994

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Grey | last post by:
I have created a asp.net form for user to input data. After input the data, user need to click a button to export the input data to excel for data analysis with excel pivot table function. is it...
5
by: JayDawg | last post by:
Is there any way to create a pivot table in a report? I have a query with the fields Date, Name, and Data, and I am trying to create a report that has the dates running across the top (like...
9
by: PeteCresswell | last post by:
I've got something called "Reference Rates". The idea is that on a given day, we have various rates of return for various entities. e.g. Libor 3-month return, Libor 6-month return, US Treasury...
0
by: salad | last post by:
I have A97 and A2003. I created a form using the Pivot Table wizard. This creates an unbound form with an embedded OLE object containing a Pivot table in Excel. There are 2 controls when the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.