MSSQL检查SELECT语句是否将包含行,如果是,则执行相同的SELECT语句

时间:2020-07-07 12:38:43

标签: sql sql-server select stored-procedures

我想在存储过程中执行SELECT语句,但是在执行之前,我必须知道它是否将包含行。如果没有,我必须跳到指定的Label,并设置输出。 我当前的方法可以正常工作,但是在几个过程中我将需要更多这些方法,我想知道是否可以在没有代码重复的情况下(并且没有Ctrl + C,Ctrl + V)做到这一点 (这只是示例代码,不是我的真实代码)

IF EXISTS (
        SELECT *
          FROM sample s
          INNER JOIN sample2 s2 ON s.Id = s2.sId
          WHERE s2.number = @input
        )
        BEGIN
            INSERT INTO @Temp
            SELECT *
              FROM sample s
              INNER JOIN sample2 s2 ON s.Id = s2.sId
              WHERE s2.number = @input
        END
    ELSE
        BEGIN
            SET @noresult = 1;
            GOTO label;
        END

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

为什么不只加载表格并随后检查?

            var pipeline = _mlContext.Transforms.ResizeImages(resizing: ImageResizingEstimator.ResizingKind.Fill, outputColumnName: "data", imageWidth: 640, imageHeight: 360, inputColumnName: nameof(ImageInputData.Image))
            .Append(_mlContext.Transforms.ExtractPixels(outputColumnName: "image_tensor", inputColumnName: "data", outputAsFloatArray: false))
            .Append(_mlContext.Model.LoadTensorFlowModel(tfModelFilePath)
                                .ScoreTensorFlowModel(
                                    outputColumnNames: InputImageSettings.OutputNodes,
                                    inputColumnNames: InputImageSettings.InputNodes,
                                    addBatchDimensionInput: false));


        var emptyData = new List<ImageInputData>();
        var data = _mlContext.Data.LoadFromEnumerable(emptyData);

        ITransformer mlModel = pipeline.Fit(data);

如果所有表的INSERT INTO @Temp SELECT * FROM sample s JOIN sample2 s2 ON s.Id = s2.sId WHERE s2.number = @input; IF NOT EXISTS (SELECT 1 FROM @temp) BEGIN SET @noresult = 1; GOTO label; END; 都相同,则在加载一堆临时表后只能有一个@noresult