We help IT Professionals succeed at work.
Get Started

SQL 2008 Columns to Rows

pposton asked
Last Modified: 2012-08-14
I have some code that I recieved help on from EE but I have one more questions concerning this code.  How would I convert the columns to rows.  This seems to be an eaiser format when using with DetailsView or in Pie Charts.  I am thinking that it probably involves a Pivot or Unpivot but I'm not sure exactly how to go about attaing the desired results.  I've attached the query below.


SELECT income
FROM client

-- This returns counts for multiple ranges
      COUNT(CASE WHEN a.income BETWEEN 0 AND 150 THEN a.income END) as count_0_150,
      COUNT(CASE WHEN a.income BETWEEN 151 AND 300 THEN a.income END) as count_151_300,
      COUNT(CASE WHEN a.income BETWEEN 301 AND 450 THEN a.income END) as count_301_450,
      COUNT(CASE WHEN a.income BETWEEN 451 AND 600 THEN a.income END) as count_451_600
      SELECT CAST(income as numeric) as income
      FROM client
      WHERE ISNUMERIC(income) = 1
	  ) a 

Open in new window

Watch Question
Project Architect
This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE