Solved

Investing columns by rows in MS SQL

Posted on 2011-03-14
8
260 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:alphaau
Comment Utility
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
Comment Utility
varchar and float...
0
 
LVL 7

Expert Comment

by:alphaau
Comment Utility
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
 
LVL 1

Author Comment

by:tenriquez199
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Author Comment

by:tenriquez199
Comment Utility
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
Comment Utility
I've also tried to invest my gridview in. net but neither have been
0
 
LVL 7

Accepted Solution

by:
alphaau earned 500 total points
Comment Utility
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
Comment Utility
ok
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

743 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now