我创建了一个程序 ( sp_ET1_ClassificacaoPPIInferior
) 来按分数 ( )对表 ( ) 中已经存在的候选人Numr_TotalEt1
的特定类别 ( ) 进行排序:TipoPrograma = 1
CandidatosVestAtual
CREATE TABLE [dbo].[CandidatosVestAtual](
[NUMG_Candidato] [bigint] NOT NULL,
[CODG_Curso] [varchar](4) NOT NULL,
[TipoPrograma] [int] NOT NULL,
[Numr_TotalEt1] [int] NULL,
[Numr_Classificacao_PPIInf_Et1] [int] NULL,
CONSTRAINT [PK_CandidatosVestAtual_1] PRIMARY KEY CLUSTERED ([NUMG_Candidato] ASC)
)
遵循使用的程序代码:
ALTER PROCEDURE [dbo].[sp_ET1_ClassificacaoPPIInferior] @CODG_Curso varchar(4)
AS
DECLARE @Cnt INT
DECLARE @NUMG_Candidato INT
DECLARE Candidatos_C CURSOR FOR
SELECT NUMG_Candidato
FROM CandidatosVestAtual
WHERE TipoPrograma in (1) AND
Codg_Curso =@CODG_Curso
ORDER BY Numr_TotalEt1 DESC
set @Cnt = 1
OPEN Candidatos_C
FETCH NEXT FROM Candidatos_C INTO @NUMG_Candidato
WHILE (@@FETCH_STATUS = 0)
BEGIN
UPDATE CandidatosVestAtual SET Numr_Classificacao_PPIInf_Et1=@Cnt
FROM CandidatosVestAtual
WHERE NUMG_Candidato=@NUMG_Candidato
SET @Cnt = @Cnt + 1
FETCH NEXT FROM Candidatos_C INTO @NumG_Candidato
END
CLOSE Candidatos_C
DEALLOCATE Candidatos_C
然而,这个过程没有做任何事情。仅当我更改原始查询过程时,它才做了一些事情:
SELECT NUMG_Candidato
FROM CandidatosVestAtual
WHERE TipoPrograma in (1)
AND Codg_Curso = @ CODG_Curso
ORDER BY DESC Numr_TotalEt1
经过
SELECT NUMG_Candidato
FROM CandidatosVestAtual
WHERE Codg_Curso = @CODG_Curso
ORDER BY DESC Numr_TotalEt1
如何使该过程与原始查询一起使用?