Solved

PIVOT TABLE - SQL Server 2000

Posted on 2007-04-11
3
224 Views
Last Modified: 2010-05-18
Hello.  I am trying to develop an ASP.NET app that displays linear data as a pivot table, and I have no idea how to go about it. My table is set up like this:
VESSEL
VOYAGE
PORT
ARRIVAL
I want this to display in a table like the following:
VESSEL   VOYAGE   PORT1   PORT2   PORT3   (Ports are different)
vsl1          voy1          date1      date2    date3
vsl2          voy2          date1      date2    date3
vsl3          voy3          date1      date2    date3

Can somebody help me with this? In Access, this is pretty easy, but how do I do this in SQL Server 2000?
0
Comment
Question by:adwooley2
  • 2
3 Comments
 
LVL 18

Expert Comment

by:Sham Haque
ID: 18887956
here's a nice explanation of how to achieve this, using CASE:

Creating cross tab queries and pivot tables in SQL
http://www.simple-talk.com/sql/t-sql-programming/creating-cross-tab-queries-and-pivot-tables-in-sql/
0
 
LVL 18

Accepted Solution

by:
Sham Haque earned 500 total points
ID: 18887975
your example:

SELECT vessel
            ,voyage
            ,port1 = CASE PORT WHEN 'port1' then arrival else null end
            ,port2  = CASE PORT WHEN 'port2' then arrival else null end
            ,port3 = CASE PORT when 'port3' then arrival else null end
FROM voyages
0
 

Author Comment

by:adwooley2
ID: 18888289
Appears easy.  I'll give it a try.  Thanks for your quick response.

Regards,
Alan
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Join & Write a Comment

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

744 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

11 Experts available now in Live!

Get 1:1 Help Now