0
-- =============================================

ALTER PROCEDURE [dbo].[NST_GetCboCurrencyAfterUpdate]
@AccCurrency nvarchar(3)='',

@AccSgroup nvarchar(6)= '',

@AccInternalCie int=null

AS

BEGIN

SET NOCOUNT ON;

    IF @AccInternalCie is not null and @AccCurrency <> '' and @AccSgroup <> ''
    Begin
    SELECT * FROM TblAccounts Where 
   AccInternalCie = @AccInternalCie and AccCurrency = @AccCurrency and AccSgroup = @AccSgroup ORDER BY AccDescription

   End 


    Else if @AccInternalCie is not null and @AccCurrency <> ''
   Begin
   SELECT * FROM TblAccounts Where 
   AccInternalCie = @AccInternalCie and AccCurrency = @AccCurrency ORDER BY AccDescription
   END

   Else if @AccInternalCie is not null and @AccSgroup <> ''
   Begin
   SELECT * FROM TblAccounts Where 
   AccInternalCie = @AccInternalCie and AccSgroup = @AccSgroup ORDER BY AccDescription
   END

    Else if @AccCurrency <> '' and @AccSgroup <> ''
   Begin
   SELECT * FROM TblAccounts Where 
   AccCurrency = @AccCurrency and AccSgroup = @AccSgroup ORDER BY AccDescription
   END
  Else if @AccSgroup <> '' 
   Begin
   SELECT * FROM TblAccounts Where 
    AccSgroup = @AccSgroup 
    Print @AccSgroup
   END
    Else if @AccCurrency <> '' 
   Begin
   SELECT * FROM TblAccounts Where 
    AccCurrency = @AccCurrency ORDER BY AccDescription
   END
     Else if @AccInternalCie is not null 
   Begin
   SELECT * FROM TblAccounts Where 
   AccInternalCie = @AccInternalCie 
   END

end 

次のストアドプロシージャがあります。SQLSERVERMANAGEMENTSTUDIOでデバッグをテストするにはどうすればよいですか。特定のクエリがどのように実行されているか。

Select * from TblAccounts where AccSGroup = '1000'

AccSGroupだけが''と等しくないと言うので

   Else if @AccSgroup <> ''       
    Begin
    SELECT * FROM TblAccounts 
    Where AccSgroup = @AccSgroup 
    Print @AccSgroup
   END

クエリを実行し、残りをバイパスする必要があります

4

1 に答える 1

0

''に等しい場合は常に、入力パラメーターをnullに設定するようにストアドプロシージャを変更する必要があると思います。

したがって、ロジックを実行する前に、プロシージャの開始時にこれを実行してください。

if @AccCurrency ='' 
BEGIN
     set @AccCurrency = null
END
if @AccSgroup ='' 
BEGIN
     set @AccSgroup = null
END

次に、ロジックを変更して<>''のチェックを削除し、代わりにチェックがnullになるようにします

したがって、以下のように行を変更します。

IF @AccInternalCie is not null and @AccCurrency <> '' and @AccSgroup <> ''

これに..

IF @AccInternalCie is not null and @AccCurrency  is not null and @AccSgroup  is not null 

次に、これを使用してストアドプロシージャをテストします。

exec [dbo].[NST_GetCboCurrencyAfterUpdate]
@AccCurrency =null,
@AccSgroup = 'your value',
@AccInternalCie =null

これで必要な結果が得られるはずです!!

DBレイヤーコードを変更してnull/空白値をチェックし、代わりにパラメーター値を設定するときにDBNull.Valueを渡します。例

if(AccCurrency.Trim().Equals(string.Empty))
{
    ParameterAccCrurrency.Value = DBNull.Value;
}
else
{
    ParameterAccCrurrency.Value = AccCurrency;
}
于 2012-10-31T06:14:14.183 に答える