It is technically possible, although I doubt if it's good practice:
- Get the result for Total into a variable:
DECLARE @total INT = (SELECT ... FROM ...)
- Create a temporary table using dynamic SQL. Make sure to create a global temp table (using the ## prefix), or it will not be available for the rest of the script
DECLARE @sql VARCHAR(MAX)
SET @sql = 'CREATE TABLE ##temptable (Present[' + @total + '] INT NOT NULL) ON [PRIMARY]'
EXECUTE (@sql);
GO
- Run your original query and put the results into the temp table
SELECT .... INTO ##temptable FROM ..........
- Select your results from the temptable:
SELECT * FROM ##temptable
| Present[20] |
| 9 |
| 5 |
| 6 |
| 7 |