Wrox Home  
Search P2P Archive for: Go

  Return to Index  

sql_language thread: Re: Pivot/data rotation conundrum


Message #1 by Roland Boorman <r_boorman@y...> on Fri, 1 Jun 2001 02:17:27 -0700 (PDT)
Hi,

it can be done through SQL.

let's assume that the 'select ... from ...' statement results as below:

	Count | CallType
	----------------
	   21 | User Err
	   18 | UI Help
	   30 | Install

now, u put this statement in another as temporary table

select
      user_err = min ( case when calltype = 'user err' then count else null
end ),
	UI_Help = min ( case when calltype = 'UI_Help' then count else null
end ),
	Install = min ( case when calltype = 'Install' then count else null
end )
from
(
select
...
from
...
) stm

it should result 
	User Err | UI Help | Install
	----------------------------
	      21 |      18 |      30

HTH
Mas

> -----Original Message-----
> From:	Brian Smith [SMTP:brian.smith@r...]
> Sent:	Thursday, 31 de May de 2001 4:20
> Subject:	Pivot/data rotation conundrum
> 
> I have a query that uses an aggregate function (count), and returns two 
> rows of data.  To be more specific, I'm pulling a list of support calls: 
> one call is the call type, the other is the number of calls.
> 
> The problem is, sadly, that the known call types aren't static, so a 
> normal pivot a la what's presented in Books Online will not work.
> 
> Is there any way to rotate my two colums of data to be a single row with 
> many colums?  For demonstration:
> 
> My normal data:
> 
> Count | CallType
> ----------------
>    21 | User Err
>    18 | UI Help
>    30 | Install
> 
> Needs to become:
> 
> User Err | UI Help | Install
> ----------------------------
>       21 |      18 |      30
> 
> Ultimately I can get around this, but I'd love to know how I can do this 
> because it would save a bit on code complexity in my VB application.
> 
> Any help would be appreciated!
> 
> Cheers,
> Brian


  Return to Index