向各位高手们请教一个sql语句,想实现这样一个结果:
内容 姓名
他在哪 是谁
我是 谁 你们
你们好吗? 累 不
累不累 关闭
想找出在“内容”一列中不包含“姓名”列中文字的行
也是就是显示这个结果
姓名
关闭
我使用的软件,不兼容charindex()函数!寻求他法!!!
谢谢各位,纯文字显示的!渴望!!
内容 姓名
他在哪 是谁
我是 谁 你们
你们好吗? 累 不
累不累 关闭
想找出在“内容”一列中不包含“姓名”列中文字的行
也是就是显示这个结果
姓名
关闭
我使用的软件,不兼容charindex()函数!寻求他法!!!
谢谢各位,纯文字显示的!渴望!!
if not object_id('Tempdb..#t') is null
drop table #t
Go
Create table #t([内容] nvarchar(5),[姓名] nvarchar(3))
Insert #t
select N'他在哪',N'是谁' union all
select N'我是 谁',N'你们' union all
select N'你们好吗?',N'累 不' union all
select N'累不累',N'关闭'
Goselect * from #t T where NOT EXISTS(SELECT 1 FROM #t WHERE replace(内容,' ','') like '%'+replace(t.姓名,' ','')+'%')(4 個資料列受到影響)
内容 姓名
----- ----
累不累 关闭(1 個資料列受到影響)
INSERT @a SELECT '他在哪','是谁',234
INSERT @a SELECT '我是谁','你们',23
INSERT @a SELECT '你们好吗?','累不',43
INSERT @a SELECT '累不累','关闭',11select * from @a a where not exists(select 1 from @a where a like '%'+a.b+'%')--result
/*a b c
-------------------- -------------------- -----------
累不累 关闭 11 (所影响的行数为 1 行)*/
create table #tb
(
内容 nvarchar(50),
姓名 nvarchar(50)
)
insert into #tb
select '他在哪 ' , '是谁' union all
select '我是 谁' , '你们' union all
select '你们好吗', '累 不' union all
select '累不累 ' , '关闭'select * from #tb t1
where not exists
(
select 1 from #tb t2
where replace(t2.内容,' ','') like '%' + replace(t1.姓名,' ','') + '%'
)drop table #tb
结果:
累不累 关闭