Hello,
I am looking to create a stored procedure that will create a table that has calculated values. I have the equation to create the columns completed and I have created the table in the stored procedure but I am unsure how insert the values to create the table from a computed column for multiple columns. This is what I currently have:
INSERT INTO AverageTest (Village, IcanbealonewhenIwish)
SELECT Village, 100.0 *
COUNT(CASE WHEN CanbealonewhenIwish IN (3,4)
THEN 1
ELSE NULL END) /
COUNT(*) AS IcanbealonewhenIwish
FROM Resident_Survey
WHERE Village = 'WP'
and Setting = 'LTC'
GROUP BY Village
UNION ALL
SELECT Village, 100.0 *
COUNT(CASE WHEN CanbealonewhenIwish IN (3,4)
THEN 1
ELSE NULL END) /
COUNT(*) AS IcanbealonewhenIwish
FROM Resident_Survey
WHERE Village = 'AT'
and Setting = 'RH'
GROUP BY Village
I have 52 columns I would like to compute into another table to get the averages for each village for each question.
Thanks