22,207
社区成员
发帖
与我相关
我的任务
分享
set nocount on
create table tb(id int,num numeric(18,8),ar varchar(10))
insert into tb select 1,12.12000000,'a'
insert into tb select 3,125.13500000,'a'
insert into tb select 4,4821.00000000,'baa'
insert into tb select 5,1245.78950000,'vav'
insert into tb select 6,120.14579210,'d'
insert into tb select 7,15478.00000000,'d'
insert into tb select 8,334200.00000000,'d'
go
create proc result(@wh varchar(100))
as
exec('select * from tb ' + @wh)
go
exec result 'where ar like ''%a%'''
drop proc result
drop table tb
set nocount off
/*
id num ar
----------- --------------------------------------- ----------
1 12.12000000 a
3 125.13500000 a
4 4821.00000000 baa
5 1245.78950000 vav
declare @Filter varchar(50),@str varchar(1000)
set @Filter='where name like ''%王%'''
set @str='select * from tb '+@Filter
exec(@str)