日期:2014-05-17 浏览次数:20681 次
CREATE PROC GET_NAME(@ID INT,@NAME VARCHAR(30) OUTPUT) AS SELECT @NAME=NAME FROM LOGIN WHERE ID=@ID GO DECLARE @NAME VARCHAR(30),@ID INT SET @ID=1 EXEC GET_NAME @ID,@NAME OUTPUT SELECT @NAME
------解决方案--------------------
--无output测试 create proc test(@galen varchar(20) output) as set @galen=@galen+'galenkeny' go declare @keny varchar(100) set @keny='test'; exec test @keny select @keny -->结果集 --------------------------------- /* test */ -- drop procedure test -->有output测试 create proc test(@galen varchar(20) output) as set @galen=@galen+'galenkeny' go declare @keny varchar(100) set @keny='test'; exec test @keny output select @keny -->结果集 --------------------------------- /* testgalenkeny */
------解决方案--------------------
搞不明白,LZ为什么要把output参数当输入参数用,感觉没必要,虽然可以这样做。下面是一个例子
CREATE PROC testProc(@ID INT,@NAME VARCHAR(30) OUTPUT) AS BEGIN SELECT @NAME --这句可以查看传入的参数值 ;WITH t as ( select 1 id,'Jason Lin' fullname union all select 2,'Kira Dong' union all select 3,'Lisa Qiu' ) SELECT @NAME=fullname FROM t WHERE id=@ID --这句是给ouutput参数赋值,以便回传给调用方 END GO DECLARE @NAME VARCHAR(30),@ID INT SET @ID=1 SET @NAME='xiaobai' --把output参数当普通输入参数使用,给其赋值 EXEC testProc @ID,@NAME OUTPUT SELECT @NAME --这句是执行完存储后,存储回传的值。