查询表数据通用存储过程
程序员文章站
2022-04-30 19:57:50
SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROC [dbo].[SearchTableData] @TableName VARCHAR(255), @Fields VARCHAR(255), @WhereField VARCHAR... ......
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'
上一篇: 函数作用域查找、闭包和匿名函数整理
下一篇: U传播:新闻稿是如何发布的?