使用针对数据表的多个可选参数实现搜索功能 [英] Implementing search functionality with multiple optional parameters against data table
本文介绍了使用针对数据表的多个可选参数实现搜索功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的国家Table.I绑定这个国家的dropdown.now我想搜索这个国家。双向
1.使用国家代码
2.使用文本。
如何编写PROCEDURE或Single查询我的问题。
tblcountry
countryCode varchar(10),
countryName varchar(10),
secCode varchar(10),
stdCountryCode varchar(10),
SELECT * FROM tblCountry WHERE countryName LIKE'%HO%';
SELECT * FROM tblCountry WHERE countryCode ='HK'
Plz帮帮我
解决方案
这对你有所帮助。
CREATE table tblcountry
(
countryCode varchar ( 10 ),
countryName varchar ( 10 ),
secCode varchar ( 10 ),
stdCountryCode varchar ( 10 )
)
GO
INSERT INTO tblcountry VALUES (' 1',' India',' 23',' 34')
INSERT INTO tblcountry VALUES ( ' 2',' 伊朗',' 273',' 344')
INSERT INTO tblcountry VALUES (' 3' ,' USA',' 345',' 678')
GO
- EXEC Sp_search'','USA'
CREATEPROC Sp_search
(
@ countryCode varchar ( 10 )= null,
@ countryName varchar ( 10 )= null
)
AS
BEGIN
IF (( @ countryCode IS NULL ) OR ( @ countryCode = ' '))
SELECT * FROM tblCountry WHERE countryName LIKE ' %' + @ countryName + ' %跨度>;
ELSE
SELECT * FROM tblCountry WHERE countryCode = @ countryCode
END
开始跨度>
This my country Table.I bind this country dropdown.now i want search this country.In two way 1.Using Country Code 2.Using Text. how to write a PROCEDURE or Single query my question. tblcountry countryCode varchar(10), countryName varchar(10), secCode varchar(10), stdCountryCode varchar(10), SELECT * FROM tblCountry WHERE countryName LIKE '%HO%'; SELECT * FROM tblCountry WHERE countryCode='HK' Plz Help me
解决方案
This will help you.
CREATE table tblcountry ( countryCode varchar(10), countryName varchar(10), secCode varchar(10), stdCountryCode varchar(10) ) GO INSERT INTO tblcountry VALUES ('1','India','23','34') INSERT INTO tblcountry VALUES ('2','Iran','273','344') INSERT INTO tblcountry VALUES ('3','USA','345','678') GO --EXEC Sp_search '','USA' CREATEPROC Sp_search ( @countryCode varchar(10) =null, @countryName varchar(10) =null ) AS BEGIN IF((@countryCode IS NULL) OR (@countryCode = '')) SELECT * FROM tblCountry WHERE countryName LIKE '%'+@countryName+'%'; ELSE SELECT * FROM tblCountry WHERE countryCode=@countryCode END Go
这篇关于使用针对数据表的多个可选参数实现搜索功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文