469,646 Members | 1,496 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,646 developers. It's quick & easy.

PIVOT / Cross Tab to Populate DataGridView

Hello and thankyou in advance for your help :)

I am developing a sales forcasting application that allows users to enter expected prices for different products by month.

I have about six months to plan this so am just doing some preliminary investigation now.

My database (which will be SQL Server) should have as a minimum, 2 tables; "Products" to store information relating to products and "Prices" to store the prices for each product.

The prices table will have as a minimum, two fields, "PriceValue" and "Date". The date value will be mmm-yy (as prices are entered for a specific month.

What I then need to achieve in my UI is a grid to display all products as row headings and my months as column headings. The data in the grid cells would then be the prices.

This structure would basically be similar to that of a pivot table or cross tab query. I have therefore been looking at the PIVOT function introduced into SQL Server 2005 and see this as a possible solution, the only problem being that you must explicitly specify the column headings you wish to use.

My Question
Is there a way in which I can dynamically add a set number of ascending months too my pivot table rather than defining them by name [Jan-07], [Feb-07] etc.?

What I would like to achieve is a stored procedure that accepts two variables, a StartDate and EndDate.
If for example, StartDate was set to Jan-07 and EndDate to July-07, the query produced would show all the prices for this date range with the column headings to match Jan-07, Feb-07, Mar-07 etc.

I appreciate any help with this as I am struggling to find examples of what I need to achieve on the net.

Thanks.
Jul 16 '07 #1
0 2316

Post your reply

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

Similar topics

reply views Thread by Prasad Patil | last post: by
4 posts views Thread by Del | last post: by
5 posts views Thread by JayDawg | last post: by
9 posts views Thread by PeteCresswell | last post: by
3 posts views Thread by David Cartwright | last post: by
reply views Thread by BenCoo | last post: by
1 post views Thread by =?Utf-8?B?SmVzcGVyLCBEZW5tYXJr?= | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.