本文介绍了在sqlserver 2008 r2中使用列值中每个单词的前2个字符进行搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 这是我的tblTest表。它有两个列,如Name,RegionThis is my tblTest table. It has two column like Name, RegionName RegionGaurav Bansal UKAlia Bansal USAlex Steven UKRahul Khare CA 这是我的查询This is my QuerySelect Name from tblTestWhere Name like 'GA%' 所以它给我结果Gaurav Bansal 现在使用相同的查询so it give me result Gaurav BansalNow using same querySelect Name from tblTestWhere Name like 'Ba%' 它没有显示任何结果但 我想要相同的结果Gaurav Bansal使用此查询 我只想显示那些结果例如,如果使用条件 像'Ga%'它应该显示结果,它只匹配表格列值中每个单词的前两个字符Gaurav Bansal因为来自Gaurav的GA比赛。 喜欢'Ba%'它应该显示结果Gaurav Bansal,Alia Bansal因为BA来自Bansal。 任何人都可以帮我摆脱这个问题 提前致谢 问候, Guptait doesn't show any result butI want same result Gaurav Bansal using this queryI want to show only those result which match only first two character of each word from column value of the table for example if use conditionlike 'Ga%' It should show result Gaurav Bansal because GA match from Gaurav.like 'Ba%' It should show result Gaurav Bansal, Alia Bansal Because BA match from Bansal.can anyone help to me to get rid of this problemThanks in advanceRegards,Gupta推荐答案Select Name from tblTestWhere Name like 'Ba%' or Name like '% Ba%'Select Name from tblTestWhere Name like '%al'; 输出: Gaurav Bansal,Alia Bansal 2.如果你在结尾处使用%运算符,它将搜索所有记录,其起始字符是给出的字符% 示例: 查询:Output :Gaurav Bansal, Alia Bansal2.If you use % operator at end then it will search all records whose starting characters is the charactes which are given befor %Example :Query :Select Name from tblTestWhere Name like 'GA%' 输出: Gaurav Bansal 3.如果你在两端使用%运算符(在开始和结束时),那么它将搜索两者之间有字符的记录。 示例: 查询:Output :Gaurav Bansal3. If you use % operator at both ends (at start and at end) then it will serach records whos having charaters in between.Example :Query :Select Name from tblTestWhere Name like '%Ba%'; 输出: Gaurav Bansal,Alia Bansal 谢谢Output :Gaurav Bansal, Alia BansalThanks 这篇关于在sqlserver 2008 r2中使用列值中每个单词的前2个字符进行搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-15 07:06