--Por favor me sugieres algo
Código SQL:
Ver originalCREATE TABLE #temp2
(
region AS VARCHAR(MAX)
TOTAl INT
)
--Msg 156, Level 15, State 1, Line 1
--Sintaxis incorrecta cerca de la palabra clave 'AS'.
--Lo que hice fue quitar el AS y quitar total int ES que no se que hace --*total INT*
CREATE TABLE #temp
(
ROW INT IDENTITY(1,1),
valor VARCHAR(20)
)
--------------------------------------------------------------------
INSERT INTO #temp VALUES ('SE')
INSERT INTO #temp VALUES ('SA')
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 --------------
SELECT @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%'
--Msg 213, Level 16, State 1, Line 55
--El nombre de columna o los valores especificados no corresponden a la definición de la tabla.
--Este error me produce conficion al parecer todo esta bien
INSERT INTO #temp2
SELECT 'REGION ' + @REGION, @TOTALF1 AS [TOTAL DE INGRESO F1]
SET @x=@x+1
END
SELECT * FROM #temp2