日期:2014-05-18  浏览次数:20533 次

sql字符查询问题?????急急急!!!!!!
create table w
(
word nvarchar(100)
)

insert into w(word)
select('去')
union all
select('第三方')
union all
select(',')
union all
select('士大夫')
union all
select('girls')
union all
select('<:')

select* from w

declare @t nvarchar(1000)
set @t='我们今天要去的地方要和第三方枯叶,顶替顶替去要夺枯地枯需要地<.'

我想从这句话中找出w表在的关键字并显示出来,包括显示几次。
结果如下:

去 2
第三方 1
, 1


大学看看该如何实现。。


------解决方案--------------------
SQL code

create table w
(
word nvarchar(100)
)

insert into w(word)
select('去')
union all
select('第三方')
union all
select(',')
union all
select('士大夫')
union all
select('girls')
union all
select(' <:')


declare @t nvarchar(1000)
set @t='我们今天要去的地方要和第三方枯叶,顶替顶替去要夺枯地枯需要地 <.'

select WORD
,LEN(@T)-LEN(REPLACE(@T,WORD,'')) 
from w WHERE LEN(@T)-LEN(REPLACE(@T,WORD,'')) >0

DROP TABLE W

/*
去    2
第三方    3
,    1
*/

------解决方案--------------------
SQL code

--是次数啊,SORRY,这次应该对了
create table w
(
word nvarchar(100)
)

insert into w(word)
select('去')
union all
select('第三方')
union all
select(',')
union all
select('士大夫')
union all
select('girls')
union all
select(' <:')


declare @t nvarchar(1000)
set @t='我们今天要去的地方要和第三方枯叶,顶替顶替去要夺枯地枯需要地 <.'

select WORD
,(LEN(@T)-LEN(REPLACE(@T,WORD,''))) /LEN(WORD)
from w WHERE LEN(@T)-LEN(REPLACE(@T,WORD,'')) >0

DROP TABLE W

/*
去    2
第三方    1
,    1
*/

------解决方案--------------------
SQL code
create table w 
( 
word nvarchar(100) 
) 

insert into w(word) 
select('去') 
union all 
select('第三方') 
union all 
select(',') 
union all 
select('士大夫') 
union all 
select('girls') 
union all 
select(' <:') 

declare @t nvarchar(1000) 
set @t='我们今天要去的地方要和第三方枯叶,顶替顶替去要夺枯地枯需要地 <.' 

select word,(len(@t)-len(replace(@t,word,'')))/len(word)
from w
where @t like '%'+word+'%'

--结果
word                                                                                                 
---------------------------------------------------------------- -----------
去                                                                                                    2
第三方                                                                                                  1
,                                                                                                    1

(3 行受影响)

------解决方案--------------------
SQL code

create table w 
( 
word nvarchar(100) 
) 

insert into w(word) 
select('去') 
union all 
select('第三方') 
union all 
select(',') 
union all 
select('士大夫') 
union all 
select('girls') 
union all 
select(' <:') 

declare @t nvarchar(1000) 
set @t='我们今天要去的地方要和第三方枯叶,顶替顶替去要夺枯地枯需要地 <.' 

select *,(len(@t)-len(replace(@t,word,'')))/len(word)
from w  where @T like '%'+word+'%'

------解决方案--------------------
create table w 

word nvarchar(100) 


insert into w(word) 
select('去') 
union all 
select('第三方') 
union all 
select(',') 
union all 
select('士大夫') 
union all 
select('girls') 
union all 
select(' <:') 

declare @t nvarchar(1000) 
set @t='我们今天要去的地方要和第三方枯叶,顶替顶替去要夺枯地枯需要地 <.' 

select word,(len(@t)-len(replace(@t,word,'')))/len(word)
from w
where @t like '%'+word+'%'

------解决方案--------------------
我顶,看看有灭有分^_^
------解决方案--------------------