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 

我有以下存储过程,我如何在 SQL SERVER MANAGEMENT STUDIO 中进行调试测试如何执行特定查询

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

然后更改您的逻辑以删除对 <> '' 的检查,而不是检查是否为空

所以改变如下线..

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 层代码以检查空值/空白值,并在设置参数值时传递 DBNull.Value。例子

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