以下のクエリを実行しようとすると、エラーが発生します
キーワード「convert」付近の構文が正しくありません
どこで間違えたのかわからない。qty フィールドのデータ型は nchar なので、convert 関数を使用して合計を求めました。
select column_date, [red] as red, [blue] as blue, [green] as green, [yellow] as yellow
from
(select * from table1) as t1
pivot
(
sum(convert(int,qty))
For color in
([red], [blue], [green], [yellow])
) as SumofQuantityforeachcolor
ここにテーブルがあります
column_date | color | qty | supplier
1 June 2012 | red | 2 | XY
1 June 2012 | red | 1 | AB
1 June 2012 | blue | 4 | CD
1 June 2012 | blue | 1 | XY
2 June 2012 | yellow| 13 | CD
2 June 2012 | green | 45 | CD
2 June 2012 | blue | 32 | AB
2 June 2012 | red | 37 | XY
2 June 2012 | red | 2 | XY
2 June 2012 | red | 1 | AB
2 June 2012 | blue | 4 | CD
3 June 2012 | red | 1 | AB
3 June 2012 | blue | 4 | CD
3 June 2012 | blue | 1 | XY
3 June 2012 | yellow| 13 | CD
3 June 2012 | green | 45 | CD
3 June 2012 | blue | 32 | AB
等々...