Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi

I have Database values with 3 fields, Im exporting this fields to Excel sheet,
I got the code to export to excel sheet, But I need modification in exporting the excel sheet,

1. The output of the excel sheet need to remove duplicates values for database and if the alarms having alarms1, alarms2 then this values show on rows


Site Node Alarms

A B alarms1
A B alarms1
A c alarms2
A B alarms2

Output of excel sheet should be


Site Node AlarmsA AlarmsB AlarmC

A B alarms1 alarms2
A c alarms2
Posted
Updated 25-Feb-15 1:00am
v2
Comments
Sergey Alexandrovich Kryukov 25-Feb-15 7:36am    
"Display in horizontal" is the UI concept. Data is neither "horizontal" nor "vertical". The answer depends on your UI and requirements...
—SA

1 solution

All you need is called Pivot[^].

SQL
SELECT Site, [alarm1],[alarm2],[alarm3]
FROM (
    SELECT Site, [Node], Alarms
    FROM TableName
    ) AS DT
PIVOT(MAX(Alarms) FOR [Node] IN([alarm1],[alarm2],[alarm3])) AS PT


Result should looks like:
Site B       C
A    Alarms1  NULL
A    Alarms2  NULL
A    NULL    Alarms2


Note that there is no way to pivot data the way you want.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900