저장 프로 시저에서 +10으로 값을 증가 시키려면 매우 간단한 명령문을 사용해야합니다. 그러나 SP를 두 번 이상 실행하면 첫 번째 호출 후에 값이 변경되지 않습니다. 증가 값을 +20으로 수정하면 결과 테이블 값은 테이블에 설정된 ORIGINAL 값의 +20이됩니다.SQL UPDATE 저장 표현식이 업데이트되지 않습니다.
USE [DB]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[spUpdateCareerRankFromInterviewByID](
-- Add the parameters for the stored procedure here
@studentID int
)
AS
BEGIN
DELETE FROM StudentCategoryRankTable
WHERE studentID = @studentID
INSERT INTO StudentCategoryRankTable (studentID, occupationalCategoryID, categoryWeightedTotal)
SELECT studentID, occupationalCategoryID, SUM(weightedResponse) AS weightedResponseTotal
FROM dbo.weightedInterviewResponsesView
GROUP BY studentID, occupationalCategoryID
HAVING (studentID = @studentID)
ORDER BY weightedResponseTotal DESC
-- Determine whether the student only wants to pursue
DECLARE @certificateOnlyQuestionOptionID INTEGER = 250
DECLARE @highMathQuestionOptionID INTEGER = 43
DECLARE @highReadingQuestionOptionID INTEGER = 47
DECLARE @highWritingQuestionOptionID INTEGER = 51
DECLARE @certificateOnlyOptionAnswered INTEGER = NULL
DECLARE @highMathQuestionOptionAnswered INTEGER = NULL
DECLARE @highReadingQuestionOptionAnswered INTEGER = NULL
DECLARE @highWritingQuestionOptionAnswered INTEGER = NULL
-- Returns 0 if the
EXEC @certificateOnlyOptionAnswered = dbo.choseQuestionOptionID @studentID = @studentID, @questionOptionID = @certificateOnlyQuestionOptionID
EXEC @highMathQuestionOptionAnswered = dbo.choseQuestionOptionID @studentID = @studentID, @questionOptionID = @highMathQuestionOptionID
EXEC @highReadingQuestionOptionAnswered = dbo.choseQuestionOptionID @studentID = @studentID, @questionOptionID = @highReadingQuestionOptionID
EXEC @highWritingQuestionOptionAnswered = dbo.choseQuestionOptionID @studentID = @studentID, @questionOptionID = @highWritingQuestionOptionID
-- Determine if the student only wants a certificate/non-degree
IF @certificateOnlyOptionAnswered != 0
BEGIN
INSERT INTO dbo.TesterTable (TestColumn) VALUES ('Certificate True')
-- High Math, add weight to scores for
-- 3: Business
-- 5: Computer Technologies
-- 7: Engineering Technology
-- 18: Sciences and Math
IF @highMathQuestionOptionAnswered != 0
BEGIN
INSERT INTO dbo.TesterTable (TestColumn) VALUES ('High Math')
UPDATE dbo.StudentCategoryRankTable
SET categoryWeightedTotal += 10
WHERE studentID = @studentID AND
occupationalCategoryID IN (3, 5, 7, 18)
END
-- High Reading/Writing, add weight to scores for
-- 4: Communications
-- 10: Humanities
-- 19: Social and Behavioral Sciences
IF @highReadingQuestionOptionAnswered != 0 OR @highWritingQuestionOptionAnswered != 0
BEGIN
INSERT INTO dbo.TesterTable (TestColumn) VALUES ('High Reading/Writing')
UPDATE dbo.StudentCategoryRankTable
SET categoryWeightedTotal += 10
WHERE studentID = @studentID AND
(occupationalCategoryID = 4 OR
occupationalCategoryID = 10 OR
occupationalCategoryID = 19)
END
END
ELSE
BEGIN
INSERT INTO dbo.TesterTable (TestColumn) VALUES ('Failed Certificate Only')
END
END
'AND oCategoryID IN (3,5,7,18)'을 사용하여 표현을 단순화 할 수 있습니다. – paqogomez
OR 섹션에 대한 SQL advice를 가져 주셔서 감사합니다. 동일한 결과 그러나 –
첫 번째 업데이트 후에 GO 문을 추가하여 커밋됩니다. – radar