能不能写关于两个字符串模糊匹配的SQL语句

2025-05-24 09:47:31
推荐回答(1个)
回答1:

模糊匹配最好用游标 不过就是速度有点慢
declare test_cursor cursor scroll for --声明游标test_cursor
select name from test --将test表中的name字段放入游标变量@name中
open test_cursor
declare @name varchar(10)

while @@fetch_status=0
begin
fetch next from test_cursor into @name
select * from table where table.name like '%'+@name+'%'
--@name与table表中的name比较
end
close test_cursor
deallocate test_cursor