存储过程中的like问题,困扰多时,高手解决!
我写的存储过程:
CREATE PROCEDURE jgTreeView1
@prID varchar(50),
@stanClass varchar(50)
AS
create table #temp(id char(50))
insert #temp values(@prID)
while exists (
select flbh from standard_frame
where flbh not in (select id from #temp)
and parentID in (select id from #temp)
)
insert #temp
select flbh from standard_frame
where flbh not in (select id from #temp)
and parentID in (select id from #temp)
declare @s varchar(1000)
if(@stanClass!= 'null ')
begin
set @s = 'select standard_Detail.* from standard_Detail,standard_frame ' + 'where (standard_Detail.class_number =standard_frame.flbh and ' + '
standard_frame.flbh in (select id from #temp) ) and standard_Detail.standard_number like " '+@stanClass+ '% " '
end
else
begin
set @s = 'select standard_Detail.* from standard_Detail,standard_frame ' + 'where standard_Detail.class_number =standard_frame.flbh and ' + '
standard_frame.flbh in (select id from #temp) '
end
print(@s)
drop table #temp
GO
怎么查询不出数据来?!我怀疑是like语句处的写法有问题,高手帮忙,用户等着要呢!
------解决方案-------------------- CREATE PROCEDURE jgTreeView1
@prID varchar(50),
@stanClass varchar(50)
AS
create table #temp(id char(50))
insert #temp values(@prID)
while exists (
select flbh from standard_frame
where flbh not in (select id from #temp)
and parentID in (select id from #temp)
)
insert #temp
select flbh from standard_frame
where flbh not in (select id from #temp)
and parentID in (select id from #temp)
declare @s varchar(1000)
if(@stanClass!= 'null ')
begin
set @s = 'select standard_Detail.* from standard_Detail,standard_frame ' + 'where (standard_Detail.class_number =standard_frame.flbh and ' + '
standard_frame.flbh in (select id from #temp) ) and standard_Detail.standard_number like ' '% '+@stanClass+ '% ' ' '/*******************这里做了改动***********************/
end
else
begin
set @s = 'select standard_Detail.* from standard_Detail,standard_frame ' + 'where standard_Detail.class_number =standard_frame.flbh and ' + '
standard_frame.flbh in (select id from #temp) '
end
exec(@s)
drop table #temp
GO
------解决方案--------------------我一般这样的
set @key = '% ' + @key + '% '
select * from tbname where title like @key
------解决方案--------------------set @s = 'select standard_Detail.* from standard_Detail,standard_frame ' + 'where (standard_Detail.class_number =standard_frame.flbh and ' + 'standard_frame.flbh in (select id from #temp) ) and standard_Detail.standard_number like ' ' '+@stanClass+ '%