join the MSSQLTips community

Today's Site Sponsor


 

SQL Compare quickly and easily compares and synchronizes SQL Server database schemas
 



Speed up SQL script deployment

Cross tab queries with SQL Server 2000

Written By: Greg Robidoux -- 6/15/2006 -- read/post comments -- print -- Bookmark and Share

Rating: (not rated yet) Rate

Problem
In SQL Server 2000 there is no simple way to create a cross tab query.  Generally crosstab queries are only used for reporting or if you want to display some information in a grid on an application screen.  Other then displaying or reporting on data there isn't a real need for this type of query.  But when the need arises for either one of these reasons, there is no simple way of doing this in SQL Server 2000.  This may come as a big surprise to people that have been doing this in Microsoft Access for quite some time. With Microsoft Access there is a built in option to produce crosstab queries, but not so with SQL Server 2000.

Solution
As mentioned above there is no simple way to produce a cross tab query, but several implementations have been produced and are available on the internet.  Finding all of these options, understanding them, implementing and testing takes some time, so to make your life a little easier we have gathered a list of some useful variations on how to produce cross tab queries in SQL Server 2000.

The following solution is pretty straight forward and offers a lot of flexibility.  Although it met my needs, take a look at the other options as well to see which one makes the most sense for your needs.

This is a list of various implementations and methods for creating crosstab queries for SQL Server 2000. There are probably others out there as well.

Some other options that do not require T-SQL coding include the following:

Next Steps

  • Take a look at these various methods for creating crosstab queries
  • Select a method that works best for your environment
  • Modify these methods to implement the right solution for your needs
Readers Who Read This Tip Also Read Free Live Webcast Comment or Ask Questions About This Tip


Wasting time running multiple scripts against multiple SQL Servers manually?

Try SQL Multi Script and execute all those scripts with just one mouse click.

Execute multiple scripts against multiple SQL Servers with a single click

"Just tried SQL Multi Script and very impressed with it. Talk about reducing work load!"

Neil Abrahams SQL Server DBA/Developer

SQL Multi Script Red Gate Software - ingeniously simple tools

Get Our Tips Newsletter

We keep 50,000+ SQL Server professionals informed.



Idera - SQL diagnostic manager

Idera SQL diagnostic manager is an award-winning performance monitoring solution for SQL Server that provides agent-less, real-time monitoring, customizable alerting, and extensive historical reporting. SQL diagnostic manager also puts must-have troubleshooting information at the DBA’s fingertips such as worst-performing code, long-running or frequently run queries, and blocking or blocked sessions.

Download now!

More SQL Server Tools
SQL Backup

SQL Compare

SQL Refactor

SQL Prompt

SQL compliance manager


Sponsor Information
Free SQL Server performance monitoring dashboard – Idera SQL check

Increase your SQL speed and accuracy with code completion from SQL Prompt.

Make the most out of SQL Server - Guaranteed Results - Innovative SQL Server DBAs

All SQL Server, all the time! Sign-up for the MSSQLTips newsletter!

Free Whitepaper - Top Ten Steps to Secure Your SQL Server



Copyright (c) 2006-2010 Edgewood Solutions, LLC All rights reserved
privacy statement | disclaimer | copyright | advertise | write for mssqltips | feedback | about
Some names and products listed are the registered trademarks of their respective owners.


CareerQandA.com | MSSharePointTips.com | MSSQLTips.com