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
我已经编写了这样的程序,用于根据农民名称搜索数据,但我想根据农民名称和类型的一个下拉列表搜索数据。 type包含两个值farmer和agent。如果我只想搜索农民,我该如何编写程序请帮助我...
答案 0 :(得分:2)
试试这个,如果你没有从下拉列表中选择任何内容,请确保将null值传递给存储过程
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
答案 1 :(得分: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 Type=@Type order by farmername
END
GO
试试这个