我写了一个存储过程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''

解决方案 »

  1.   

    create proc proc_list
    @tableName varchar(100),
    @where varchar(100)
    as
    exec('select * from [' + @tableName + '] where ' + @where)
      

  2.   


    create proc proc_list 
    @tableName varchar(100), 
    @where varchar(100) 
    as 
    exec('select * from'+ @tableName+'  where'+ @where )
    exec proc_list 'users','username='aaa''
      

  3.   

    create proc proc_list 
    @tableName varchar(100), 
    @where varchar(100) 
    as 
     exec('select * from '+@tableName+'  where '+@where)
    go
    exec proc_list 'users','username=''aaa'''
      

  4.   


    create proc proc_list 
    @tableName varchar(100), 
    @where varchar(100) 
    as 
    exec('select * from'+ @tableName+'  where'+ @where )
    exec proc_list 'users','username=''aaa'''
      

  5.   

    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'''
      

  6.   


    'fromusers' 附近有语法错误。
      

  7.   


    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'''少打了空格
      

  8.   

    create proc proc_list 
    @tableName varchar(100), 
    @where varchar(100) 
    as 
    exec('select * from [' + @tableName + '] where ' + @where)