?
Solved

Investing columns by rows in MS SQL

Posted on 2011-03-14
8
Medium Priority
?
312 Views
Last Modified: 2012-06-27
How do I do next?



I Have a DataBase like in IMAGE 1

AND I need a query that show me somethin like IMAGE 2


I try with PIVOT but i cant do that this work



db1.png
DB2.png
0
Comment
Question by:tenriquez199
  • 5
  • 3
8 Comments
 
LVL 7

Expert Comment

by:Alpha Au
ID: 35134561
i think it should be done in client instead of sql server,

in you image 2, the what datatype are you going to use for the 2 columns??
0
 
LVL 1

Author Comment

by:tenriquez199
ID: 35134565
varchar and float...
0
 
LVL 7

Expert Comment

by:Alpha Au
ID: 35134599
the database table doesn't not support using TWO datatype in ONE column!!

can you explain further about why (or where) you need to show the data in the way of Image 2?
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
LVL 1

Author Comment

by:tenriquez199
ID: 35134630
Ohmggg really I dont need "JUGOS" in the column, Actually i need only the types FLOAT

In mi IMAGE 1 i have a SELECT * FROM MyTable....

And this is a result but i need some query to show something like IMAGE 2

ALMATO            GOLD
     0                        20
    2                         10

It's for application in .NET

I Investigate some for PIVOT but i cant do that work PIVOT...

PLEASE HELP ME!!
0
 
LVL 1

Author Comment

by:tenriquez199
ID: 35134754
I've done something similar with PIVOT, but only managed to place a row and I need at least two rows

THIS IS THE QUERY THAT I  USE!!

SELECT [Almato], [Bob Esponja],[Confrutta], [Frutte],[Gold], [Happy Day],[JC Chavez],[Maui],[Saha],[Sonrisa],[TreeTop],[Vredondo], [Good 4 You], [Total]
FROM (SELECT  [Marca_pro], [IMPORTE] FROM [Sicom].[dbo].[jde11$]
where Tipo='JUGOS'  and dia='3' and mes='1' )
p PIVOT (SUM([IMPORTE])
FOR [Marca_pro] IN ([Almato], [Bob Esponja],[Confrutta], [Frutte],[Gold], [Happy Day],[JC Chavez],[Maui],[Saha],[Sonrisa],[TreeTop],[Vredondo], [Good 4 You], [Total])) AS pvt;
0
 
LVL 1

Author Comment

by:tenriquez199
ID: 35134762
I've also tried to invest my gridview in. net but neither have been
0
 
LVL 7

Accepted Solution

by:
Alpha Au earned 2000 total points
ID: 35146191
Hi, i would suggest to transpose the datatable in application level.

please try this link

http://www.eggheadcafe.com/tutorials/aspnet/5c5d810e-20e6-4d6c-a0a3-5277ba8de7e7/transpose-a-datatable-in.aspx
0
 
LVL 1

Author Closing Comment

by:tenriquez199
ID: 35335706
ok
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Suggested Courses

840 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