8

「選択」を1回だけ使用するように以下のコードを改善するにはどうすればよいですか?

IF EXISTS (SELECT [NUMBER] FROM [TABLE] WHERE [ID_RECORD] = @id_record
BEGIN
   DECLARE @tmp_variable
   SELECT @tmp_variable = [NUMBER] FROM [TABLE] WHERE [ID_RECORD] = @id_record

   SET @other_variable = @tmp_variable
END
ELSE
BEGIN
   SET @other_variable = 0
END
4

2 に答える 2

19

これを試して :

 DECLARE @tmp_variable INT
 SET @tmp_variable = ISNULL(( SELECT    [NUMBER]
                              FROM      [TABLE]
                              WHERE     [ID_RECORD] = @id_record
                             ), 0)
于 2013-05-16T08:35:53.070 に答える