Solved

Investing columns by rows in MS SQL

Posted on 2011-03-14
8
280 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
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:alphaau
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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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:
alphaau 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Update trigger 5 18
sql server tables from access 18 19
Create snapshot on MSSQL 2012 3 19
SQL Server Import/Error Wizard error 12 19
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
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.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

778 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