Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Investing columns by rows in MS SQL

Posted on 2011-03-14
8
286 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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 500 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

789 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