Código SQL:
Ver originalCREATE TABLE #temp2
(
region AS VARCHAR(MAX)
TOTAl INT
)
CREATE TABLE #temp
(
ROW INT IDENTITY(1,1),
valor VARCHAR(20)
)
INSERT INTO #temp VALUES ('SE')
INSERT INTO #temp VALUES ('SA')
INSERT INTO #temp VALUES (N)
DECLARE @FASE AS VARCHAR(1)
SET @FASE = '1'
DECLARE @FASE2 AS VARCHAR(1)
SET @FASE2 = '2'
DECLARE @REGION AS VARCHAR(2)
DECLARE @TOTALF1 AS INT
DECLARE @x INT
SET @x=1
--while @x<=(select [B](count(*)[/B] from #temp)
--debe de ser
while @x<=(SELECT COUNT(*) FROM #temp)
BEGIN
--- Segmento destacado Aqui esta el error --------------
SET @REGION = valor FROM #temp WHERE ROW=@x
--------------------------------------------
SELECT @TOTALF1 = COUNT(C.[Nombre RH])
FROM S_VW_Cursos A
INNER JOIN COURSE_USERS B ON B.CRSMAIN_PK1 = A.PK1
INNER JOIN S_VW_Usuarios C ON C.PK1 = B.USERS_PK1
INNER JOIN GRADEBOOK_MAIN D ON D.CRSMAIN_PK1 = A.PK1
INNER JOIN GRADEBOOK_GRADE E ON E.GRADEBOOK_MAIN_PK1 = D.PK1 AND E.COURSE_USERS_PK1 = B.PK1
INNER JOIN ATTEMPT F ON F.PK1 = E.HIGHEST_ATTEMPT_PK1
WHERE D.Title = 'BAJA'
AND B.ROLE = 'S'
AND A.Clave LIKE '%EC-F'+@FASE+'-' + @REGION + '%'
AND A.Clave NOT LIKE '%PDC%'
AND A.Clave NOT LIKE '%PT%'
INSERT INTO #temp2
SELECT 'REGION ' + @REGION, @TOTALF1 AS [TOTAL DE INGRESO F1]
SET @x=@x+1
END
SELECT * FROM #temp2