Solved

PIVOT TABLE - SQL Server 2000

Posted on 2007-04-11
3
267 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
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.

710 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