create proc test @table varchar(100),@条件1 varchar(8000),@条件2 varchar(8000),@条件3 varchar(8000)
as
declare @sql varchar(2000)
set @sql = 'select * from ' + @table + ' where 1 = 1 '
exec(@sql + isnull(@条件1,'') + ' '+isnull(@条件2,'') + ' ' +isnull(@条件3,''))
go
--调用
exec test 'tablename','and col1 > 0','and col2 > 0','and col3 > 0'
@条件写成: and ......
as
declare @sql varchar(2000)
set @sql = 'select * from ' + @table + ' where 1 = 1 '
exec(@sql + isnull(@条件1,'') + ' '+isnull(@条件2,'') + ' ' +isnull(@条件3,''))
go
--调用
exec test 'tablename','and col1 > 0','and col2 > 0','and col3 > 0'
@条件写成: and ......
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货