怀疑Sql Server在查询中 [英] Doubt on Sql Server in query

查看:97
本文介绍了怀疑Sql Server在查询中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

晚安非常好

域名:SQL Server





问题:

如何在不使用LIKE运算符的情况下从下面的查询中检索(或)过滤数据?



 创建  stu(sname  varchar  50 ))

insert 进入 stu ' karthick '),(' kannan'),(' suresh'),(' rajesh'),(' mahesh'),(' muthu'),(' gopal'
选择 * 来自 stu

选择 sname 来自 stu 其中 sname 喜欢 ' %esh%'





解决这个问题..



谢谢&问候

Karthick

解决方案

您可以使用全文搜索: MSDN [ ^ ]但这对于这样一个简单的工作来说可能有点过头了,看起来像你所展示的LIKE一样。


1)什么''错误的喜欢

2)如果由于某种原因你不能使用这个算子,你可能需要重新设计整个事物

3)你可以使用正则表达式,但默认情况下不支持它,它比资源更昂贵,比如

4)你可以使用PATINDEX [ ^ ]功能,但我认为它甚至比使用像

5)在你的样本中,所有esh都在字符串的末尾,如果在所有情况下都是真的,你可以使用正确 [ ^ ] function


like operator是最简单的方法,你可以检索记录与其他函数比较。

查看此链接



http://www.w3schools.com /sql/sql_like.asp [ ^ ]



否则



你可以使用CONTAINS

  SELECT  *  FROM  table_name  WHERE   CONTAINS (column_name,' * value *'



查看此链接了解更多信息

http://msdn.microsoft.com/ EN-US /库/ ms187787%28V = SQL.105%29.aspx


Hi Everyone,
Very Good Evening
Domain: SQL Server


Question:
How to retrieve (or) filter data from below query without using LIKE operator?

create table stu(sname varchar(50))

insert into stu values('karthick'),('kannan'),('suresh'),('rajesh'),('mahesh'),('muthu'),('gopal')
select * from stu

select sname from stu where sname like '%esh%'



Solve this Problem..

Thanks & Regards
Karthick

解决方案

You could use a full text search: MSDN[^] but it''s probably overkill for such a simple job, that looks tailor made for LIKE from what you show.


1) What''s wrong with like?
2) If you can''t use this operator for whatever reason, you probably need to redesign the whole thing
3) You could use regular expressions, but it is not supported by default, and it is much more resource-expensive than like
4) You can use PATINDEX[^] function, but I think it is even a little bit more complicated than using like
5) In you samples all "esh" are at the end of the string, if it is true in all cases, you can use RIGHT[^] function


like operator is the simplest way ,you can retrieve the records compare with other functions.
check this link

http://www.w3schools.com/sql/sql_like.asp[^]

otherwise

You can use CONTAINS

SELECT * FROM table_name WHERE CONTAINS(column_name , '"*value*"')


check this link for more info
http://msdn.microsoft.com/en-us/library/ms187787%28v=sql.105%29.aspx


这篇关于怀疑Sql Server在查询中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆