Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
shki_80
Starting Member
3 Posts |
Posted - 2009-08-18 : 04:16:35
|
| I have table with fields Q1, Q2, Q3, Q4 etc having range of values like A(Excellent), B(Very Good), C(Good), D(Fair), E(Not good).Now I want to retrieve the data with single query like A B C D EQuestion 1 5 2 3 4 5Question 2 6 0 1 0 3Question 3 10 12 23 3 0But the questions are in fields, Is ther anybody helps in this case.Pls. anybody helps. What is the query to retrieve the above result.Shakeel, Web Developer |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-08-18 : 04:21:22
|
| use pivot functionselect question,[a],[b],[c],[d],[e]from tablenamepivot (max(values) for types in ([a],[b],[c],[d],[e]))p |
 |
|
|
shki_80
Starting Member
3 Posts |
Posted - 2009-08-18 : 04:31:42
|
| We can shift column into rows through PIVOT, Currently I have seen that PIVOT function is used to shift rows into columnsShakeel, Web Developer |
 |
|
|
waterduck
Aged Yak Warrior
982 Posts |
Posted - 2009-08-18 : 04:54:29
|
quote: table with fields Q1, Q2, Q3, Q4
hi, is there any column other than this 4 column? Hope can help...but advise to wait pros with confirmation... |
 |
|
|
shki_80
Starting Member
3 Posts |
Posted - 2009-08-18 : 05:50:08
|
| yes there are many columns Q1, Q2, Q3, .......Q26But I want result like A B C D E Q1 5 2 0 6 8Q2 6 3 6 9 2Q3 9 6 9 7 2...Q26 10 8 9 6 9Like column of the table into rowsHope you understand. I think Pivot function is being used but how pivot column into rows.Shakeel, Web Developer |
 |
|
|
Nageswar9
Aged Yak Warrior
600 Posts |
Posted - 2009-08-18 : 07:06:44
|
| for this , use dynamic cross tab it is useful for u |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-08-18 : 07:15:09
|
| can u post some sample data ? |
 |
|
|
waterduck
Aged Yak Warrior
982 Posts |
Posted - 2009-08-18 : 22:33:49
|
hm...is there any method other than dynamic query? Hope can help...but advise to wait pros with confirmation... |
 |
|
|
|
|
|
|
|