当前位置: 代码迷 >> Sql Server >> 存储过程,变量处理方式,自定义显示列,该如何处理
  详细解决方案

存储过程,变量处理方式,自定义显示列,该如何处理

热度:58   发布时间:2016-04-27 12:24:47.0
存储过程,变量处理方式,自定义显示列,
table
id name number
1 fdfdfd 3223
2 dfdfdf 4566
存过程如下:
create procedure Ptest(in id int)
begin
select * from table where id=id;
end;//
call Ptest('1')//
将得到
第一行。
问题是:
我要实理,只定义,输出name,或number只要一列,如何实现呢?就是,我让他
类似这样一个函数
function(id,lie){
select lie from table where id = id
}

因此我的过程这样写,但不写变量如何处理
create procedure Ptest(in id int,in lie varchar(20))
begin
select lie from table where id=id;
end;//
call Ptest('1')//
输出的结果不对。应该怎么写啊???

------解决方案--------------------
SQL code
create procedure Ptest(@id int,@lie varchar(20))beginexec('select [email protected]+' from table where id='+ltrim(@id))