Hi there,
I've got a problem writing a view in SQL Server 7, what I would like to do is create a view (or infact write a sp)that takes values from one table and generates percentage results from those values. for example...
My table = Question1 answertxt1 Question2 answertxt2
Age 1 Location 5
Age 4 Location 2
Age 2 Location 2
Age 1 Location 4
I want to create a sp procedure that takes these values and makes a table that displays the data thus...
Results table = answertxt1 percent1 answertxt2 percent2
1 20% 1 75%
2 15% 2 0%
3 30% 3 5%
4 35% 4 20%
and so on..
Currently I have this
select convert(dec(15,2),100.00* count(*)/(select count(*)from stp_survey WHERE answertxt1 = '1'
OR answertxt1 = '2'
OR answertxt1 = '3'
OR answertxt1 = '4'
OR answertxt1 = '5')) AS answertxt1
from stp_survey
WHERE answertxt1 = '1'
OR answertxt1 = '2'
OR answertxt1 = '3'
OR answertxt1 = '4'
OR answertxt1 = '5'
Group by answertxt1
but I don't know how to do all the other columns, this will display what percent1 looks like. I do have a column called id which is a unique field I think maybe this is what should be used instead of Group By answertxt1
Any ideas?
I've got a problem writing a view in SQL Server 7, what I would like to do is create a view (or infact write a sp)that takes values from one table and generates percentage results from those values. for example...
My table = Question1 answertxt1 Question2 answertxt2
Age 1 Location 5
Age 4 Location 2
Age 2 Location 2
Age 1 Location 4
I want to create a sp procedure that takes these values and makes a table that displays the data thus...
Results table = answertxt1 percent1 answertxt2 percent2
1 20% 1 75%
2 15% 2 0%
3 30% 3 5%
4 35% 4 20%
and so on..
Currently I have this
select convert(dec(15,2),100.00* count(*)/(select count(*)from stp_survey WHERE answertxt1 = '1'
OR answertxt1 = '2'
OR answertxt1 = '3'
OR answertxt1 = '4'
OR answertxt1 = '5')) AS answertxt1
from stp_survey
WHERE answertxt1 = '1'
OR answertxt1 = '2'
OR answertxt1 = '3'
OR answertxt1 = '4'
OR answertxt1 = '5'
Group by answertxt1
but I don't know how to do all the other columns, this will display what percent1 looks like. I do have a column called id which is a unique field I think maybe this is what should be used instead of Group By answertxt1
Any ideas?