我写了一个存储过程proc_list,
create proc proc_list
@tableName varchar(100),
@where varchar(100)
as
select * from @tableName where @where
他需要提供参数@tableName和@where,用于查询指定表的中符合where条件的记录
我想执行这个存储过程,但是在写条件的时候不知道应该怎么写了
这样?
exec proc_list 'users' 'username='aaa''
调试欢乐多
@tableName varchar(100),
@where varchar(100)
as
exec('select * from [' + @tableName + '] where ' + @where)
create proc proc_list
@tableName varchar(100),
@where varchar(100)
as
exec('select * from'+ @tableName+' where'+ @where )
exec proc_list 'users','username='aaa''
@tableName varchar(100),
@where varchar(100)
as
exec('select * from '+@tableName+' where '+@where)
go
exec proc_list 'users','username=''aaa'''
create proc proc_list
@tableName varchar(100),
@where varchar(100)
as
exec('select * from'+ @tableName+' where'+ @where )
exec proc_list 'users','username=''aaa'''
@tableName varchar(100),
@where varchar(100)
as
exec('select * from'+ @tableName+' where1=1 AND '+ @where )exec proc_list 'users','username=''aaa'''
'fromusers' 附近有语法错误。
create proc proc_list
@tableName varchar(100),
@where varchar(100)
as
exec('select * from '+ @tableName+' where1=1 AND '+ @where )exec proc_list '[users]','username=''aaa'''少打了空格
@tableName varchar(100),
@where varchar(100)
as
exec('select * from [' + @tableName + '] where ' + @where)