本文介绍了如何从列表中搜索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在storeprocedure中编写了这个查询。但是使用这个我只能用完整的文本搜索数据。例如:我可以搜索名称为'''ronak''的数据。我无法搜索名称以''开头的数据R ''。



请帮我解决这个问题。





SELECT profile .name1 AS name,profile.address,profile.mob_no,profile.emailid,login.username

FROM profile INNER JOIN

登录ON profile.log_id = login.log_id

WHERE(profile.name1 LIKE @ name1)或

(profile.mob_no LIKE @mob_no)或

(profile.emailid LIKE @emailid)或者

(login.username LIKE @username)



我尝试了以下2解决方案,但是当我写查询时





SET @ name1 =''%''+ @ name1 +''%''



SELECT profile.name1 AS name,profile.address,profile.mob_no,profile.emailid,login.username

FROM profile INNER JOIN

登录ON profile.log_id = login.log_id

WHERE(profile.name1 LIKE @ name1)或

(profile.mob_no LIKE @mob_no)或

(个人资料。 emailid LIKE @emailid )或者

(login.username LIKE @username)

然后它适用于名称文本框。当我写查询时



SET @ name1 =''%''+ @ name1 +''%''

SET @mob_no =''%''+ @mob_no +''%''

SET @emailid =''%''+ @emailid +''%''

SET @username =''%''+ @username +''%' '



SELECT profile.name1 AS name,profile.address,profile.mob_no,profile.emailid,login.username

FROM profile INNER加入

登录ON profile.log_id = login.log_id

WHERE(profile.name1 LIKE @ name1)或

(profile.mob_no LIKE @ mob_no)或

(profile.emailid LIKE @emailid)或

(login.username LIKE @username)

然后它不起作用任何文本框。

I have written this query in storeprocedure.But using this I can only search data with complete text.For Example:I can search data whose name=''ronak''.i can not search data whose name start with ''r''.

please help me how to do this.


SELECT profile.name1 AS name, profile.address, profile.mob_no, profile.emailid, login.username
FROMprofile INNER JOIN
login ON profile.log_id = login.log_id
WHERE (profile.name1 LIKE @name1) OR
(profile.mob_no LIKE @mob_no) OR
(profile.emailid LIKE @emailid) OR
(login.username LIKE @username)

I have try below 2 solution ,but when I write query


SET @name1 = ''%'' + @name1 + ''%''

SELECT profile.name1 AS name, profile.address, profile.mob_no, profile.emailid, login.username
FROMprofile INNER JOIN
login ON profile.log_id = login.log_id
WHERE (profile.name1 LIKE @name1) OR
(profile.mob_no LIKE @mob_no) OR
(profile.emailid LIKE @emailid) OR
(login.username LIKE @username)
then it is working for name textbox.And when I write query

SET @name1 = ''%'' + @name1 + ''%''
SET @mob_no = ''%'' + @mob_no + ''%''
SET @emailid = ''%'' + @emailid + ''%''
SET @username = ''%'' + @username + ''%''

SELECT profile.name1 AS name, profile.address, profile.mob_no, profile.emailid, login.username
FROMprofile INNER JOIN
login ON profile.log_id = login.log_id
WHERE (profile.name1 LIKE @name1) OR
(profile.mob_no LIKE @mob_no) OR
(profile.emailid LIKE @emailid) OR
(login.username LIKE @username)
then it is not working for any textbox.

推荐答案

SELECT profile.name1 AS name, profile.address, profile.mob_no, profile.emailid, login.username
FROM profile INNER JOIN
login ON profile.log_id = login.log_id
WHERE     
(profile.name1 LIKE @name1 +'%') OR
(profile.mob_no LIKE @mob_no +'%') OR
(profile.emailid LIKE @emailid +'%') OR
(login.username LIKE @username +'%')


SET @name1 = '%' + @name1 + '%'
SET @mob_no = '%' + @mob_no + '%'
SET @emailid = '%' + @emailid + '%'
SET @username = '%' + @username + '%'

SELECT profile.name1 AS name, profile.address, profile.mob_no, profile.emailid, login.username
  FROM profile INNER JOIN
          login ON profile.log_id = login.log_id
 WHERE profile.name1 LIKE @name1 
    OR profile.mob_no LIKE @mob_no
    OR profile.emailid LIKE @emailid
    OR login.username LIKE @username


这篇关于如何从列表中搜索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 08:43