Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a history sp

Status
Not open for further replies.

abienz

Programmer
Aug 13, 2001
53
GB
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?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top