34,576
社区成员
发帖
与我相关
我的任务
分享
declare @str nvarchar(100)
set @str = '机械应用程序'
select * from tb where charindex(keywords,@str)>0
declare @str nvarchar(100)
set @str = '机械应用程序'
select * from tb where charindex(keywords,@str)>0
方法貼重
重貼方法
use Tempdb
go
--> -->
if not object_id(N'Tempdb..#T') is null
drop table #T
Go
Create table #T([num] int,[keywords] nvarchar(2))
Insert #T
select 1,N'中华' union all
select 2,N'机械' union all
select 3,N'学习' union all
select 4,N'程序'
Go
DECLARE @str NVARCHAR(1000)
SET @str='机械应用程序'
Select * from #T WHERE PATINDEX('%'+keywords+'%',@str)>0
/*
num keywords
2 机械
4 程序*/
use Tempdb
go
--> -->
if not object_id(N'Tempdb..#T') is null
drop table #T
Go
Create table #T([num] int,[keywords] nvarchar(2))
Insert #T
select 1,N'中华' union all
select 2,N'机械' union all
select 3,N'学习' union all
select 4,N'程序'
Go
DECLARE @str NVARCHAR(1000)
SET @str='机械应用程序'
Select * from #T WHERE @str LIKE '%'+keywords+'%' ORDER BY num
/*
num keywords
2 机械
4 程序*/
select num from tb where '机械应用程序' like '%'+keywords+'%'