Solved

PIVOT TABLE - SQL Server 2000

Posted on 2007-04-11
3
248 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
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…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

785 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