2013-10-25 91 views
2
alter PROCEDURE K_HM_SearchFarmeragentDet 
@Type varchar(50),@farmername varchar(50) 
AS 
BEGIN 

    SET NOCOUNT ON; 
SELECT MHA.sno,MHA.farmername,MHA.referencedby,HMB.Branch,MHA.area,MHA.contactno,MHA.Type from k_Master_AddHatchingFarmer MHA inner join 
K_HM_Branch HMB on MHA.Branch=HMB.Sno where farmername like @farmername+'%' order by farmername 

END 
GO 

我已經寫了這樣的程序來搜索基於farmername的數據,但我想搜索基於farmername的數據以及Type的一個下拉列表。類型包含農民和代理兩個值。如果我想只搜索農民,我該怎麼寫程序,請幫我...基於兩個條件搜索文本框和下拉列表?

+0

什麼數據庫是什麼? SQL Server就是它的樣子。 – logixologist

+0

是的,sqlserver 2005是..... – santhosha

+0

我們可以看到你使用的代碼在這個下拉列表中傳遞......這將有很大的幫助。 – logixologist

回答

2
alter PROCEDURE K_HM_SearchFarmeragentDet 
    @Type varchar(50),@farmername varchar(50) 
    AS 
    BEGIN 

    SET NOCOUNT ON; 
    SELECT MHA.sno,MHA.farmername,MHA.referencedby,HMB.Branch,MHA.area,MHA.contactno,MHA.Type from k_Master_AddHatchingFarmer MHA inner join 
    K_HM_Branch HMB on MHA.Branch=HMB.Sno where farmername like @farmername+'%' and [email protected] order by farmername 

    END 
    GO 

試試這個

2

試一下,如果你沒有從下拉列表中選擇任何東西,一定要將空值傳遞給存儲過程

ALTER PROCEDURE K_HM_SearchFarmeragentDet 
@Type varchar(50),@farmername varchar(50) 
AS 
BEGIN 
SET NOCOUNT ON; 
SELECT MHA.sno,MHA.farmername,MHA.referencedby,HMB.Branch,MHA.area,MHA.contactno,MHA.Type from k_Master_AddHatchingFarmer MHA inner join 
K_HM_Branch HMB on MHA.Branch=HMB.Sno 
where farmername like @farmername+'%' 
AND MHA.Type = ISNULL(@Type, MHA.Type) 
order by farmername 
END 
GO 
相關問題