2012-10-31 24 views
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 

查詢應執行和休息必須繞過

回答

1

我想你應該改變你的存儲過程來設置輸入參數爲空,無論他們是等於「」

這樣做在你的程序中的任何之前你的邏輯執行的開始..

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 

這應該讓你需要的結果!

更改您的數據庫層代碼以檢查空/空值並在設置參數值時傳遞DBNull.Value。 例

if(AccCurrency.Trim().Equals(string.Empty)) 
{ 
    ParameterAccCrurrency.Value = DBNull.Value; 
} 
else 
{ 
    ParameterAccCrurrency.Value = AccCurrency; 
} 
+0

如果你能幫我所有的排列和除了一個我已經發布關於它工作在SQL Server而不是在前端asp.net – vini

+0

組合工作,那麼可能有一些問題與如何你從asp.net調用SP。你能在這裏粘貼這些代碼嗎? –

+0

已添加DataAccessLayer代碼 – vini

相關問題