Link to home
Start Free TrialLog in
Avatar of tenriquez199
tenriquez199

asked on

Investing columns by rows in MS SQL

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
Avatar of Alpha Au
Alpha Au
Flag of Hong Kong image

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??
Avatar of tenriquez199
tenriquez199

ASKER

varchar and float...
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?
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!!
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;
I've also tried to invest my gridview in. net but neither have been
ASKER CERTIFIED SOLUTION
Avatar of Alpha Au
Alpha Au
Flag of Hong Kong image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ok