如题:
CREATE PROCEDURE [dbo].[ReturnPayKey_no]
@Key_no varchar(1000) output,
@P_type varchar(1000),
@input_date datetime,
@Opter varchar(100)
AS
BEGIN
SET NOCOUNT ON
declare @code varchar(100)
declare @i int
declare @ii int
declare @input varchar(6)
declare @str varchar(10)
set @code=(select ptype_code from t_ptype where [email protected]_type);
set @input=(select replace(CONVERT(char(7),@input_date,111),'/',''));
set @i=(select isnull(max(Convert(int,right(key_no,3))),0) from t_payout where [email protected]_type and [email protected]_date and [email protected])+1;
set @ii=len(Convert(varchar(10),@i))
if @ii=1
begin
set @str='00'+Convert(varchar(10),@i)
end
else if @ii=2
begin
set @str='0'+Convert(varchar(10),@i)
end
else
begin
set @str=Convert(varchar(10),@i)
end
set @[email protected][email protected][email protected]
select @Key_no
return @@error
END
CREATE PROCEDURE [dbo].[InserIntoPayout]
@Pay_id int output,
@Key_no varchar(1000) output,
@Input_d datetime,
@Input_date datetime,
@Onput_date datetime,
@Opter varchar(1000),
@State int,
@P_type varchar(100),
@Nominal varchar(1000)
AS
BEGIN
SET NOCOUNT ON;
Exec ReturnPayKey_no @Key_no,@P_type,@Input_d,@Opter
print @Key_no
END
------解决方案--------------------
如果是单一值,参考:
- SQL code
D. 使用 OUTPUT 参数OUTPUT 参数允许外部过程、批处理或多条 Transact-SQL 语句访问在过程执行期间设置的某个值。下面的示例创建一个存储过程 (titles_sum),并使用一个可选的输入参数和一个输出参数。首先,创建过程:USE pubsGOIF EXISTS(SELECT name FROM sysobjects WHERE name = 'titles_sum' AND type = 'P') DROP PROCEDURE titles_sumGOUSE pubsGOCREATE PROCEDURE titles_sum @@TITLE varchar(40) = '%', @@SUM money OUTPUTASSELECT 'Title Name' = titleFROM titles WHERE title LIKE @@TITLE SELECT @@SUM = SUM(price)FROM titlesWHERE title LIKE @@TITLEGO接下来,将该 OUTPUT 参数用于控制流语言。 说明 OUTPUT 变量必须在创建表和使用该变量时都进行定义。参数名和变量名不一定要匹配,不过数据类型和参数位置必须匹配(除非使用 @@SUM = variable 形式)。 DECLARE @@TOTALCOST moneyEXECUTE titles_sum 'The%', @@TOTALCOST OUTPUTIF @@TOTALCOST < 200 BEGIN PRINT ' ' PRINT 'All of these titles can be purchased for less than $200.'ENDELSE SELECT 'The total cost of these titles is $' + RTRIM(CAST(@@TOTALCOST AS varchar(20)))下面是结果集:Title Name ------------------------------------ The Busy Executive's Database GuideThe Gourmet MicrowaveThe Psychology of Computer Cooking(3 row(s) affected)Warning, null value eliminated from aggregate. All of these titles can be purchased for less than $200.
------解决方案--------------------
------解决方案--------------------
- SQL code
存储过程之间的相互调用
第一种方法: 使用output参数
USE AdventureWorks;
GO
IF OBJECT_ID ( 'Production.usp_GetList', 'P' ) IS NOT NULL
DROP PROCEDURE Production.usp_GetList;
GO
CREATE PROCEDURE Production.usp_GetList @product varchar(40)
, @maxprice money
, @compareprice money OUTPUT
, @listprice money OUT
AS
SELECT p.name AS Product, p.ListPrice AS 'List Price'
FROM Production.Product p
JOIN Production.ProductSubcategory s
ON p.ProductSubcategoryID = s.ProductSubcategoryID