Saturday, February 25, 2012

Crosstab?

Hello,
I have this:
Part Month Type
0001A 10/2004 EM
0001A 10/2004 MM
0001A 11/2004 EM
Would like to get to this:
Part Month EM MM
0001A 10/2004 1 1
0001A 11/2004 1 0
thanks
stevehttp://www.aspfaq.com/2462
Please post DDL, sample data and desired results.
See http://www.aspfaq.com/5006 for info.
"steve9" <steve9@.gmail.com> wrote in message
news:1111523038.812065.303570@.f14g2000cwb.googlegroups.com...
> Hello,
> I have this:
> Part Month Type
> 0001A 10/2004 EM
> 0001A 10/2004 MM
> 0001A 11/2004 EM
> Would like to get to this:
> Part Month EM MM
> 0001A 10/2004 1 1
> 0001A 11/2004 1 0
> thanks
> steve
>|||Try,
select
Part,
[Month],
count(case when Type = 'EM' then 1 end) as EM,
count(case when Type = 'MM' then 1 end) as MM,
from
table1
group by
Part,
[Month];
HOW TO: Rotate a Table in SQL Server
http://support.microsoft.com/defaul...574&Product=sql
AMB
"steve9" wrote:

> Hello,
> I have this:
> Part Month Type
> 0001A 10/2004 EM
> 0001A 10/2004 MM
> 0001A 11/2004 EM
> Would like to get to this:
> Part Month EM MM
> 0001A 10/2004 1 1
> 0001A 11/2004 1 0
> thanks
> steve
>|||Simple...thx
"Alejandro Mesa" <AlejandroMesa@.discussions.microsoft.com> wrote in message
news:E9A4EAE8-A669-49FE-9C99-40125D798F22@.microsoft.com...
> Try,
> select
> Part,
> [Month],
> count(case when Type = 'EM' then 1 end) as EM,
> count(case when Type = 'MM' then 1 end) as MM,
> from
> table1
> group by
> Part,
> [Month];
> HOW TO: Rotate a Table in SQL Server
> http://support.microsoft.com/defaul...574&Product=sql
>
> AMB
> "steve9" wrote:
>|||If anyone is looking for the BMW of crosstabs as opposed
to the Chevy version check out the RAC utility for S2k:)
www.rac4sql.net

No comments:

Post a Comment