关于contains

linseng129 2008-03-21 11:55:25
如果是按照常规的检索,那么应该是contains(ColName,'关键词')对吗?
但是现在问题是反过来,我的关键词是ColName里面的值,而被检索的是"关键词"也就是用户输入的字符串,这个怎么检索啊?
...全文
714 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
wzy_love_sly 2008-03-21
  • 打赏
  • 举报
回复
sorry 没听懂哦
linseng129 2008-03-21
  • 打赏
  • 举报
回复
sql语句:select top 10 字段名 from tb_name where patindex(字段名,被查询的字符串变量)>0
这里是指在"被查询的字符串变量"中找出包含"字段名"的值的记录
linseng129 2008-03-21
  • 打赏
  • 举报
回复
wzy_love_sly,问题是'%'+s+'%' 我这里是字段里本来就有的值怎么办?
wzy_love_sly 2008-03-21
  • 打赏
  • 举报
回复
不行?
linseng129 2008-03-21
  • 打赏
  • 举报
回复
顶!!!
wzy_love_sly 2008-03-21
  • 打赏
  • 举报
回复
declare @tb table (s varchar(50))
insert into @tb select 'abc'
insert into @tb select 'ab'
insert into @tb select 'ac'

select * from @tb
where patindex('%'+s+'%','abcd')>0


abc
ab
zheninchangjiang 2008-03-21
  • 打赏
  • 举报
回复
在程序中可以参数
然后参数值=用户输入字符串,不知道你是用什么写程序的
wzy_love_sly 2008-03-21
  • 打赏
  • 举报
回复
一个意思
linseng129 2008-03-21
  • 打赏
  • 举报
回复
所以呀,我郁闷呀,不过还是要谢谢你的
wzy_love_sly 2008-03-21
  • 打赏
  • 举报
回复
contains就查列里包含字符吧,语法就那样,感觉不行吧
linseng129 2008-03-21
  • 打赏
  • 举报
回复
可以是可以了
但是速度很慢,用contains会快点吗?
wzy_love_sly 2008-03-21
  • 打赏
  • 举报
回复
create table tb(col1 varchar(5))
insert into tb select 'ab'
insert into tb select 'cd'
insert into tb select 'ef'

declare @v varchar(20)
set @v='acdefg '
select * from tb
where patindex('%'+col1+'%',@v)>0


cd
ef
linseng129 2008-03-21
  • 打赏
  • 举报
回复
表已经建立全文索引并填充
linseng129 2008-03-21
  • 打赏
  • 举报
回复
表tb1
col1
ab
cd
ef


关键词:acdefg


需要从表中找出来的是 cd 和 ef
wzy_love_sly 2008-03-21
  • 打赏
  • 举报
回复
给点数据,还有你用的查询语句,估计大家都没看懂你说的意思
linseng129 2008-03-21
  • 打赏
  • 举报
回复
查不出来数据,但没出错
wzy_love_sly 2008-03-21
  • 打赏
  • 举报
回复
那就我那样写啊 s不就是列了,

declare @tb table (s varchar(50))
insert into @tb select 'abc'
insert into @tb select 'ab'
insert into @tb select 'ac'
包含在'abcd'里的有
abc
ab
2个,不对吗?
linseng129 2008-03-21
  • 打赏
  • 举报
回复

就是现有列名里面的值
wzy_love_sly 2008-03-21
  • 打赏
  • 举报
回复
sorry 什么叫‘数据表字段里本身就有的值’,不就是列名吗?
linseng129 2008-03-21
  • 打赏
  • 举报
回复
就是patindex里第一个参数,不是输入进去的,是数据表字段里本身就有的值
这是第六版的介绍《ASP.NET 4入门经典:涵盖C#和VB.NET(第6版)》内容简介:ASP.NET是.NET Framework的一部分,用于构建内容丰富的动态Web站点。其最新的版本ASP.NET 4对上一版进行了许多改进,包括增强了Web窗体,并添加了jQuery的支持。《ASP.NET 4入门经典:涵盖C#和VB.NET(第6版)》循序渐进,逐步讲解了如何使用ASP.NET 4构建内容丰富的Web站点,并提供了大量使用C#和VB的示例。通过实际动手练习,您将学到关于构建Web站点的第一手信息,同时能够深刻理解在浏览器中查看ASP.NET 4页面时,后台到底发生了什么。 这是第七版,也就是本源码书的介绍 The ultimate programming guide to ASP.NET 4.5, by popular author and Microsoft MVP Imar Spaanjaars Updated for ASP.NET 4.5, this introductory book is filled with helpful examples and contains a user-friendly, step-by-step format. Written by popular author and Microsoft ASP.NET MVP Imar Spaanjaars, this book walks you through ASP.NET, Microsoft's technology for building dynamically generated web pages. This edition retains the highly accessible approach to building the Planet Wrox website example, an online community site featuring product reviews, picture sharing, bonus content for registered users, and more. Contains the comprehensive guide to the latest technology additions to ASP.NET 4.5 Shows how to build basic ASP.NET web pages and configure their server Includes information on how to add features with pre-built server controls Reveals how to design pages and make them consistent Contains the information needed for getting user input and displaying data Beginning ASP.NET 4.5 in C# and VB uses Spaanjaars's distinct writing style to put you at ease with learning ASP.NET 4.5.

34,874

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧