用CHARINDEX返回字符串中指定表达式的起始位置,然后用SUBSTRING取出你关键字前后的一部分字 比如 declare @count int select @count=charindex('cc',t1) from tt1 where charindex('cc',t1)>0 select substring(t1,@count-5,@count+5) from tt1 where charindex('cc',t1)>0 这只是简单的提供一下思路,是可行的,只要区别@count的几种情况就可以了。
你要想做成GOOGLE那种搜索的话用SQL是做不成的
我是要搜索自己的数据库,有具体的例子吗? chg515(瞎玩)的思路我想想.
where (字段1 like %关键字%) or (字段2 like %关键字%) or (字段3 like %关键字% )
用CHARINDEX返回字符串中指定表达式的起始位置,然后用SUBSTRING取出你关键字前后的一部分字 比如 declare @count int select @count=charindex('cc',t1) from tt1 where charindex('cc',t1)>0 select substring(t1,@count-5,@count+5) from tt1 where charindex('cc',t1)>0 这只是简单的提供一下思路,是可行的,只要区别@count的几种情况就可以了。
cn.ConnectionString = "Server=192.168.203.30;Database=IQC;User Id=kye;Password=kye;" cn.Open() Dim objcm As New SqlCommand Dim objad As New SqlDataAdapter Dim ds As New DataSet objcm.Connection = cnIf DropDownList1.SelectedItem.Text = "報告編號" Then objcm.CommandText = "select * from iqcreport where iqc_bh like '%" + TextBox1.Text + "%'" objad.SelectCommand = objcm objad.Fill(ds)
返回字符串中指定表达式的起始位置。
具体用法查SqlServer帮助
SELECT * FROM a WHERE id in ( SELECT id+1,id-1 FROM a WHERE youwant LIKE ~~~ )
呵呵,是这个意思吗?我瞎写,没试过。
谢谢大家!!
比如
declare @count int
select @count=charindex('cc',t1)
from tt1
where charindex('cc',t1)>0
select substring(t1,@count-5,@count+5)
from tt1 where charindex('cc',t1)>0
这只是简单的提供一下思路,是可行的,只要区别@count的几种情况就可以了。
chg515(瞎玩)的思路我想想.
比如
declare @count int
select @count=charindex('cc',t1)
from tt1
where charindex('cc',t1)>0
select substring(t1,@count-5,@count+5)
from tt1 where charindex('cc',t1)>0
这只是简单的提供一下思路,是可行的,只要区别@count的几种情况就可以了。
like关键字能用单方向就单方向的
最好做成存储过程吧
cn.Open()
Dim objcm As New SqlCommand
Dim objad As New SqlDataAdapter
Dim ds As New DataSet
objcm.Connection = cnIf DropDownList1.SelectedItem.Text = "報告編號" Then
objcm.CommandText = "select * from iqcreport where iqc_bh like '%" + TextBox1.Text + "%'"
objad.SelectCommand = objcm
objad.Fill(ds)