我想这就是你所追求的:
USE [Product] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER Proc [Controls].[spSiloSettings] @Silo int ,@PartNo Varchar (50) ,@Slow float output ,@Close float output ,@errorout int output AS BEGIN declare @found bit = 0 set @errorout = 0 select @slow = slow , @close = close , @found = 1 from controls.TableA where silo = @silo and partno = @partno if @found != 1 begin select top 1 @found = 1 , @slow= slow , @close = close From controls.TableB Where silo = @silo --order by something to ensure consistent results? if @found = 1 begin insert into controls.TableA (silo, partno, slow, close) values (@silo, @partno ,@slow, @close) end else begin @errorout = 1 --neither A nor B held the value we were after end end END