set ansi_nulls on go set quoted_identifier on go alter proc [dbo].[searchtabledata] @tablename varchar(255), @fields varchar(255), @wherefield varchar(255), @wherevalue varchar(255) as begin declare @sql varchar(255) declare @xtype int=0 set @sql ='select '+@fields+' from '+@tablename; select @xtype=syscolumns.xtype from syscolumns, systypes where syscolumns.xusertype = systypes.xusertype and syscolumns.id = object_id(@tablename)and syscolumns.name=@wherefield if(@xtype=0) begin raiserror ('修改字段不存在', 16, 1) end set @sql=@sql+' where '+@wherefield+'=' if(@xtype=48 or @xtype=52 or @xtype=56 or @xtype=62or @xtype=127) begin set @sql=@sql+@wherevalue; end else if(@xtype=35or @xtype=99 or @xtype=167 or @xtype=175 or @xtype=231 or @xtype=239) begin set @sql=@sql+''''+@wherevalue+''''; end else raiserror ('数据类型错误', 16, 1) exec (@sql) end exec searchtabledata '表名','*','countid','1'