create procedure sp_bhk
@tzd char(10)
as
declare @ysmc varchar(20),@bh char(10),@cpgg varchar(20)
declare bhk1 cursor scroll
for select tzdbh,ysmc,bh,cpgg from ymj.xmd_bhk where tzdbh like'%'+@tzd+'%'
open bhk1
fetch next from bhk1 into @tzdbh,@ysmc,@bh,@cpgg
while (@@fetch_status=0)
begin
set @tzd=ltrim(rtrim(@tzd))
print "" select tzdbh,ysmc,bh,cpgg from ymj.xmd_bhk where tzdbh=@tzd
end
close bhk1
deallocate bhk1
小姑娘 j9988(j9988)写得应该是你想要得,还有你可以用Like做模糊查询
======================================================
所有包含0600的记录,例如:01MB0600,01M0600B,010600MB
select * from ymj.xmd_bhk where tzdbh like '%0600%'
开始包含0600的,例如: 060001MB,060002MB
select * from ymj.xmd_bhk where tzdbh like '0600%'
结尾包含0600的,例如:01MB0600,02MB0600
select * from ymj.xmd_bhk where tzdbh like '%0600'
======================================================
补充一点
while (@@fetch_status=0)
begin
select tzdbh,ysmc,bh,cpgg from ymj.xmd_bhk where tzdbh=@tzdbh
fetch next from bhk1 into @tzdbh,@ysmc,@bh,@cpgg
end
改为
while (@@fetch_status=0)
begin
set @tzdbh=ltrim(rtrim(@tzdbh))
select tzdbh,ysmc,bh,cpgg from ymj.xmd_bhk where tzdbh=@tzdbh
fetch next from bhk1 into @tzdbh,@ysmc,@bh,@cpgg
end
create procedure sp_bhk
@tzdbh varchar(15)
as
declare @ysmc varchar(20),@bh char(10),@cpgg varchar(20)
declare bhk1 cursor scroll
for select tzdbh,ysmc,bh,cpgg from ymj.xmd_bhk where tzdbh like'%@tzdbh%'
open bhk1
fetch next from bhk1 into @tzdbh,@ysmc,@bh,@cpgg
while (@@fetch_status=0)
begin
select tzdbh,ysmc,bh,cpgg from ymj.xmd_bhk where tzdbh=@tzdbh
fetch next from bhk1 into @tzdbh,@ysmc,@bh,@cpgg
end
close bhk1
deallocate bhk1
create procedure sp_bhk
@tzdbh varchar(15)
as
declare @ysmc varchar(20),@bh char(10),@cpgg varchar(20)
declare bhk1 cursor scroll
for select tzdbh,ysmc,bh,cpgg from ymj.xmd_bhk where tzdbh like'%@tzdbh%'
open bhk1
fetch next from bhk1 into @tzdbh,@ysmc,@bh,@cpgg
while (@@fetch_status=0)
begin
print "" select tzdbh,ysmc,bh,cpgg from ymj.xmd_bhk where tzdbh=@tzdbh
end
close bhk1
deallocate bhk1
declare af cursor for select id from AAA
open af
fetch next from af into @id
WHILE @@FETCH_STATUS = 0
begin
delete from AAA where id = @id
fetch next from af into @id
end
close af
DEALLOCATE af