我有一个存储过程如下:
ALTER PROCEDURE [dbo].[sp_web_orders_insert] ( @userId int = default,@custId int = default,@orderDate datetime = default,@orderTotal money = default,@statusId int = default,@orderReference varchar(50) = default,@custReference varchar(50) = default,@order_ID INT output,@orderReferenceOutput varchar(50) output ) AS SET NOCOUNT OFF; INSERT INTO [web_orders] ([user_ID],[cust_ID],[orderDate],[orderTotal],[statusId],[orderReference],[custReference]) VALUES (@userId,@custId,@orderDate,@orderTotal,@statusId,'PLC' + REPLICATE('0',(7 - LEN((select MAX(order_ID) from web_orders)))) + CAST((select(max(order_ID)+1) from web_orders) AS VARCHAR(5)),@custReference); SELECT @order_ID = @@IDENTITY RETURN @order_ID SELECT @orderReferenceOutput = 'PLC' + REPLICATE('0',(7 - LEN((select MAX(order_ID) from web_orders)))) + CAST((select(max(order_ID)+1) from web_orders) AS VARCHAR(5)) RETURN @orderReferenceOutput
由于某种原因,第二个输出参数@orderReferenceOutput不返回任何内容.第二个输出参数的目的是检索刚刚插入数据库的列.