CREATE PROCEDURE am_a @str nvarchar( 10), @num int AS set nocount on declare @i int declare @char char select @i=0 select test12.*,0 as error into #temp from test12 while @i<len(@str) begin select @i=@i+1 select @char=substring(@str,@i,1) update #temp set error=error+1 where id in (select id where charindex(@char,name)=0)end select * from #temp where error<@num
test12的结构是 id int 10 name nvarchar 10
@str 是要查的字串, @num 是允许的个数! 我自己试过了,没问题
TO andynamo(编程烂指) : 万分感谢!我对SQL语法 不太清楚,请问该句是什么意思: select test12.*,0 as error into #temp from test12test12.*,0 四什么意思? error在什么地方定义?再次感谢
执行结果不对 update #temp set error=error+1 where id in (select id where charindex(@char,name)=0) 可能有错
select test12.*,0 as error into #temp from test12test12.* 是指test12这个表的所有字段, 0 as error 是指加一个名为error的字段,其初始值为0! error 可以改为其它名字! 这个存储过程有两个参数,第一个是要找的字串,第二个就是错误的个数!
update #temp set error=error+1 where id in (select id where charindex(@char,name)=0)是有错,改为: update #temp set error=error+1 where id in (select id from Test12 where charindex(@char,name)=0)
如果是4个字符,可以这么写select * from tableneme where name like 'a_c_' or 'a__d' or 'ab%' or '_b_d' or '_bc_' or '__cd'
@num int
AS
set nocount on
declare @i int
declare @char char
select @i=0
select test12.*,0 as error into #temp from test12
while @i<len(@str)
begin
select @i=@i+1
select @char=substring(@str,@i,1)
update #temp set error=error+1 where id in (select id where charindex(@char,name)=0)end
select * from #temp where error<@num
id int 10
name nvarchar 10
@num 是允许的个数!
我自己试过了,没问题
万分感谢!我对SQL语法 不太清楚,请问该句是什么意思:
select test12.*,0 as error into #temp from test12test12.*,0 四什么意思?
error在什么地方定义?再次感谢
update #temp set error=error+1 where id in (select id where charindex(@char,name)=0)
可能有错
0 as error 是指加一个名为error的字段,其初始值为0!
error 可以改为其它名字!
这个存储过程有两个参数,第一个是要找的字串,第二个就是错误的个数!
update #temp set error=error+1 where id in (select id from Test12 where charindex(@char,name)=0)
or '_b_d' or '_bc_' or '__cd'