| Author |
Topic |
|
lollie
Starting Member
1 Post |
Posted - 2011-07-08 : 07:29:39
|
| Have the following tableIFAC,IPROD, USE_PER, QTYaa ,aa345 , q1 , 100ad , ad234, q1 , 250ad , ad234, q3 , 120ba , ba124, q1 , 150want to create a view as followIFAC, IPROD, Q1, Q2, Q3, Q4aa , aa345 , 100, 0, 0, 0ad , ad234 , 250, 0, 120, 0 ba , ba124 , 150, 0, 0, 0 |
|
|
Ranjit.ileni
Posting Yak Master
183 Posts |
Posted - 2011-07-08 : 07:57:27
|
| create view <viewname>asselect IFAC, IPROD, isnull(sum(case when USE_PER = 'q1' then QTY end),0) as QTY, isnull(sum(case when USE_PER = 'q2' then QTY end),0) as QTY, isnull(sum(case when USE_PER = 'q3' then QTY end),0) as QTY, isnull(sum(case when USE_PER = 'q4' then QTY end),0) as QTYfrom <YOURTABLE>group by IFAC,IPRODgo--Ranjit |
 |
|
|
Ranjit.ileni
Posting Yak Master
183 Posts |
Posted - 2011-07-08 : 07:58:50
|
quote: Originally posted by Ranjit.ileni create view <viewname>asselect IFAC, IPROD, isnull(sum(case when USE_PER = 'q1' then QTY end),0) as q1, isnull(sum(case when USE_PER = 'q2' then QTY end),0) as q2, isnull(sum(case when USE_PER = 'q3' then QTY end),0) as q3, isnull(sum(case when USE_PER = 'q4' then QTY end),0) as q4from <YOURTABLE>group by IFAC,IPRODgo--Ranjit
--Ranjit |
 |
|
|
|
|
|