si que no puedes asignar a una variable mas de un valor por ejemplo
Código SQL:
Ver originalDECLARE @variable VARCHAR(20)
SET @variable=(SELECT SUM(1) AS total,server_name FROM #results WHERE server_name='FNTRIPLV' GROUP BY server_name ORDER BY server_name)
me marca este error:
Msg 1033, Level 15, State 1, Line 3
The ORDER BY clause IS invalid IN views, inline functions, derived TABLES, subqueries, AND common TABLE expressions, unless TOP OR FOR XML IS also specified.
quito el ORDER BY de la consulta:
DECLARE @variable VARCHAR(20)
SET @variable=(SELECT SUM(1) AS total,server_name FROM #results WHERE server_name='FNTRIPLV' GROUP BY server_name)
me marca el sig error
Msg 116, Level 16, State 1, Line 3
ONLY one expression can be specified IN the SELECT list WHEN the subquery IS NOT introduced WITH EXISTS.
que es lo que se tiene que hacer, lo siguiente:
DECLARE @variable VARCHAR(20)
SET @variable=(SELECT SUM(1) AS total FROM #results WHERE server_name='FNTRIPLV' GROUP BY server_name)
y asi tenemos el valor de la suma en la variable :)
saludos!