0
以下のストアドプロシージャが動作しますが、効率的でもエレガントではありません。 3つのクエリではなく、1つのクエリで@_score、@_comment、および@_noteの3つの値を取得する方法がありますか?SQL行からストアドプロシージャの既存の値を選択する:これを行うより効率的な方法はありますか?
ALTER PROCEDURE [dbo].[updateScore]
@sqaeid nvarchar(30),
@username nvarchar(30),
@scoreid nvarchar(30),
@score nvarchar(30),
@comment nvarchar(max),
@note nvarchar(max)
AS
/* Capture the existing three values that will get
overwritten with new data */
declare @_score as nvarchar(30)
declare @_comment as nvarchar(max)
declare @_note as nvarchar(max)
/******************************************************************/
/* Is there a more elegant, and efficient, way to do this? */
/******************************************************************/
Set @_score = (Select score from tScore where [email protected])
Set @_comment = (Select comment from tScore where [email protected])
Set @_note = (Select note from tScore where [email protected])
/******************************************************************/
/* Update the table row with the new data */
UPDATE tScore Set [email protected], [email protected], [email protected] WHERE [email protected]
/* Generate a log entry that will capture the old data and the new data in
case we want to rollback to the previous values */
INSERT into tLog
VALUES (@sqaeid, @username, GETDATE(), 'updateScore',
'score_id', @scoreid, 'new score', @score,
'new comment', @comment, 'new note', @note,
'old score', @_score, 'old comment', @_comment,
'old note', @_note);
。 tLogファイルにはIDフィールドがあるため、最初のソリューションは完全に機能しますが、2番目のソリューションは最もエレガントで効率的です。 – Jmarien