I am trying to finish the following sql view and make it so that the two columns named sorter and sorter2 can be combined using ISNULL() so that I can sort by the column.
This should be easy, i.e. use ISNULL(dbo.tblEnvScorecard.sorter, dbo.tblQuestInfo.sortOrder/100), but doing that gives me the following error:
Column 'dbo.tblQuestInfo.sortOrder' is invalid in the select list because it is not contained in either an aggregate function or the group by clause
I need to divide by 100 because a metric can be associated with many questions, but all the questions will be in the same section, as defined by the digit in the hundreds place.
Any ideas/questions?
Code:
SELECT TOP 100 PERCENT COUNT(dbo.tblMetrics.metricID) AS projCount, dbo.tblMetrics.metricID, ISNULL(dbo.tblQuestInfo.category,
ISNULL(dbo.tblEnvScorecard.title, 'UNUSED')) AS category, dbo.tblMetrics.title, dbo.tblEnvScorecard.sorter,
dbo.tblQuestInfo.sortOrder / 100 AS sorter2
FROM dbo.tblMetrics LEFT OUTER JOIN
dbo.tblEnvScorecard ON ',' + dbo.tblEnvScorecard.metric1 + ',' + dbo.tblEnvScorecard.metric2 + ',' LIKE '%,' + CAST(dbo.tblMetrics.metricID AS varchar(8))
+ ',%' LEFT OUTER JOIN
dbo.tblQuestInfo ON dbo.tblMetrics.metricID = dbo.tblQuestInfo.metricID
GROUP BY dbo.tblMetrics.metricID, dbo.tblQuestInfo.category, dbo.tblMetrics.title, dbo.tblEnvScorecard.title, dbo.tblEnvScorecard.title,
dbo.tblEnvScorecard.sorter, dbo.tblQuestInfo.sortOrder / 100
ORDER BY dbo.tblQuestInfo.category
This should be easy, i.e. use ISNULL(dbo.tblEnvScorecard.sorter, dbo.tblQuestInfo.sortOrder/100), but doing that gives me the following error:
Column 'dbo.tblQuestInfo.sortOrder' is invalid in the select list because it is not contained in either an aggregate function or the group by clause
I need to divide by 100 because a metric can be associated with many questions, but all the questions will be in the same section, as defined by the digit in the hundreds place.
Any ideas/questions?