Solved

Crosstab query in SQL

Posted on 2003-11-19
5
2,442 Views
Last Modified: 2007-12-19
Can anyone tell me how to create a crosstab query in SQL? I am connecting to an Oracle view through an ODBC connection that contains the information I want to display in a crosstab table.
0
Comment
Question by:meghu
  • 2
5 Comments
 
LVL 15

Accepted Solution

by:
namasi_navaretnam earned 250 total points
ID: 9783120
You will need to use case statement to create crosstab queries in sql server.
Example

Select col1,  ( Case Col1 WHEN 'A' THEN 1 ELSE 0 END),
                  ( Case Col1 WHEN 'B' THEN 1 ELSE 0 END),
                  ( Case Col1 WHEN 'C' THEN 1 ELSE 0 END)
from MyTable

Also look at WITH CUBE, WITH ROLLUP keywords with group statement

Example,

Select Col1, Sum(Col2)
FROM MyTable
Group By Col1 With CUBE

HTH
0
 
LVL 34

Expert Comment

by:arbert
ID: 9793335
Can you post more details.  If you have a fixed amount of values, namasi's suggestion will work fine.  If you get quite a few values, it becomes cumbersome and you might want a more dynamic solution.
0
 
LVL 15

Expert Comment

by:namasi_navaretnam
ID: 9946487
Would you need further help? If not, why not close the issue? :)

Regards.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

747 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

12 Experts available now in Live!

Get 1:1 Help Now