[RESOLVED]How to display records from a pivot query in MVC

Hi,following is my table with records

Cust	Product	QTY
KATE	VEG	2
KATE	SODA	6
KATE	MILK	1
KATE	BEER	12
FRED	MILK	3
FRED	BEER	24
KATE	VEG	3

if run following pivot query

SELECT PRODUCT, FRED, KATE
FROM (
SELECT CUST, PRODUCT, QTY
FROM Products) up
PIVOT (SUM(QTY) FOR CUST IN (FRED, KATE)) AS pvt
ORDER BY PRODUCT

i got following result

PRODUCT	FRED	KATE
---------------------- BEER 24 12 MILK 3 1 SODA NULL 6 VEG NULL 5

my requirement is to display the records from pivot query in a view in mvc application

how it is possible.

Regards

Baiju

Do you have a specific question?  Is your problem formatting the SQL?  Reading the data?  Is it an html layout issue?  As it stands your post is basically "how do I write a web site?"

Start with the mvc tutorials and go through them and all should become clear

http://www.asp.net/mvc/overview/getting-started/introduction/getting-started

For reading the data google "asp.net execute sql from ado.net" and you’ll find examples on how to do that.

klbaiju

my requirement is to display the records from pivot query in a view in mvc application

It seems your problem is to show the results of a dynamic query (your pivot query) in a view.

For showing the records, I recommend using a WebGrid. It has several features which you may leverage. Please take a look at the below post

WebGrid in ASP.NET
MVC4

Now coming to the query, please take a look at the stackoverflow post on how to do this

Parsing Dynamic SQL in C# and binding to WebGrid in ASP.Net MVC

Leave a Reply