--那要用自定义函数
--自定义函数,比较一个字符串中的字符是否与另一个字符相同
create function f_comparestr(@str1 varchar(8000),@str2 varchar(8000))
returns bit
as
begin
declare @tb1 table(st varchar(2))
declare @tb2 table(st varchar(2))
declare @i int,@re bit,@len intselect @i=1,@len=len(@str1)
while @i<=@len
begin
insert into @tb1 values(substring(@str1,@i,1))
set @i=@i+1
endselect @i=1,@len=len(@str2)
while @i<=@len
begin
insert into @tb2 values(substring(@str2,@i,1))
set @i=@i+1
endselect @re= case when exists(select 1 from @tb1 a full join @tb2 b on a.st=b.st where a.st is null or b.st is null)
then 0 else 1 end
return(@re)
end
go
--自定义函数,比较一个字符串中的字符是否与另一个字符相同
create function f_comparestr(@str1 varchar(8000),@str2 varchar(8000))
returns bit
as
begin
declare @tb1 table(st varchar(2))
declare @tb2 table(st varchar(2))
declare @i int,@re bit,@len intselect @i=1,@len=len(@str1)
while @i<=@len
begin
insert into @tb1 values(substring(@str1,@i,1))
set @i=@i+1
endselect @i=1,@len=len(@str2)
while @i<=@len
begin
insert into @tb2 values(substring(@str2,@i,1))
set @i=@i+1
endselect @re= case when exists(select 1 from @tb1 a full join @tb2 b on a.st=b.st where a.st is null or b.st is null)
then 0 else 1 end
return(@re)
end
go
create function f_comparestr(@str1 varchar(8000),@str2 varchar(8000))
returns bit
as
begin
declare @tb1 table(st varchar(2))
declare @tb2 table(st varchar(2))
declare @i int,@re bit,@len intselect @i=1,@len=len(@str1)
while @i<=@len
begin
insert into @tb1 values(substring(@str1,@i,1))
set @i=@i+1
endselect @i=1,@len=len(@str2)
while @i<=@len
begin
insert into @tb2 values(substring(@str2,@i,1))
set @i=@i+1
endselect @re= case when exists(select 1 from @tb1 a full join @tb2 b on a.st=b.st where a.st is null or b.st is null)
then 0 else 1 end
return(@re)
end
go--创建数据测试环境
declare @tb table(id int identity(1,1),aa varchar(100))
insert into @tb
select '2345671'
union all select '4567321'
union all select '7345621'
union all select '340587'
union all select '390458'
--查询结果
delete @tb
where dbo.f_comparestr(aa,'1234567')=1--显示结果
select * from @tb--删除函数
drop function f_comparestr
--自定义函数,比较一个字符串中的数字是否与另一个字符串相同
create function f_comparestr(@str1 varchar(8000),@str2 varchar(8000))
returns bit
as
begin
declare @tb1 table(st varchar(2))
declare @tb2 table(st varchar(2))
declare @i int,@re bit,@len intselect @i=1,@len=len(@str1)
while @i<=@len
begin
insert into @tb1 values(substring(@str1,@i,1))
set @i=@i+1
endselect @i=1,@len=len(@str2)
while @i<=@len
begin
insert into @tb2 values(substring(@str2,@i,1))
set @i=@i+1
endselect @re= case when exists(select 1 from @tb1 a full join @tb2 b on a.st=b.st where a.st is null or b.st is null)
then 0 else 1 end
return(@re)
end
go--创建数据测试环境
declare @tb table(id int identity(1,1),aa varchar(100))
insert into @tb
select '2345671'
union all select '4567321'
union all select '7345621'
union all select '340587'
union all select '390458'
--查询结果
delete @tb
where dbo.f_comparestr(aa,'1234567')=1--显示结果
select * from @tb--删除函数
drop function f_comparestr
----------- ------------------
4 340587
5 390458(所影响的行数为 2 行)
那帮人帮到底吧,在Access中如何实现呢?好象不能创建函数?