consider the following table
create table sample(id, name, numeric, qno, ans1,ans2,ans3)
sample data
1, 'vivek', 1, 'a', 'b', ''
2, 'vivek', 1, 'c', 'd', ''
3, 'vivek', 2, 'e', 'f', 'g'
4, 'vivek', 3, 'h', 'i', 'j'
5, 'vijay', 1, 'k', '', 'l'
6, 'vijay', 2, 'm', '', 'n'
7, 'vijay', 2, 'o', '', 'p'
8, 'vikram', 3, 'q', 'r', 's'
output expected
column Names: name, info1, info2, info3
values
'vivek','ab','ef','hij'
'vivek','cd','',''
'vijay','kl', 'mn',''
'vijay','','op',''
'vikram','','','qrs'
converting rows into columns.
in other words. one answer will have one row. there can be multiple answers to one question.
the output should have answer numbers as columns.
is there any quick and easy technique in sql 2000?
Firstly, if I understand your problem, then I think your first result should be
‘vivek’,’ab’,’efg’,’hij’ rather than ‘vivek’,’ab’,’ef’,’hij’
If so, then I think the following may do what you want.
Had a similar problem with Sql 2000 recently, so credit must go to this article on SqlServerCentral