Is there any way to set a variable within the 'THEN' clause in the statement you see below?
I just want to increment a variable in this fashion
@var = @var + 1
I'm also open to inserting rows into a temp table to get a count that way as well.. I am just not sure how to pull it off.
I would need to do the same for about 30 other case statements as well.
Example:
CASE WHEN ( ( SELECT sum(BreakerHours) / sum(DemoHours) * 100 FROM #DMData WHERE Warehouse = @Wh ) > ( SELECT highvalue FROM #ThresholdData WHERE Threshold_TypeId = 9 ) OR ( SELECT sum(BreakerHours) / sum(DemoHours) * 100 FROM #DMData WHERE Warehouse = @Wh ) < ( SELECT lowvalue FROM #ThresholdData WHERE Threshold_TypeId = 9 ) ) THEN ( SELECT 'Weekly Average ' + '(' + LEFT(CONVERT(VARCHAR(10), '8/14/2013', 101), 5) + ' to ' + LEFT(CONVERT(VARCHAR(10), '8/20/2013', 101), 5) + ')' AS [TD] ,cast(round(sum(BreakerHours) / sum(DemoHours) * 100, 2) AS NUMERIC(36, 2)) AS [TD] FROM #DMData WHERE Warehouse = 782 FOR XML raw('tr') ,Elements ) ELSE '' END
Any help is really appreciated,
regards, -c