嗨,我还是 TSQL 的新手。如何输出标量变量以便我的 vb 代码可以访问它?
在 VB 中,我使用 rs 方法。在这种情况下,我必须创建 3 个 rs 才能访问下面的数据。我想要一个存储过程,它可以在不使用多个 rs 的情况下为我提供所需的 4 个值。
Create PROCEDURE [dbo].[sp_tblTransaction_GET_All_Totals]
@TransID bigint
AS
Declare @MyTotalCharges as money
Declare @MyTotalDiscounts as money
Declare @MyTotalPayments as money
Declare @TotalCharges as money
Declare @TotalDiscounts as money
Declare @TotalPayments as money
Declare @Balance as money
SELECT @MyTotalCharges = SUM(Amount)
FROM tblTransactionDetails
WHERE (TransID = @TransID)
SELECT @MyTotalDiscounts = SUM(Amount)
FROM tblTransaction_DP
WHERE (TransID = @TransID)
SELECT @MyTotalPayments = SUM(Amount)
FROM tblPayments
WHERE (TransID = @TransID)
--Below are the scalar values I need to be ouputed and accessed by my vb app.
--How can I output the values below?
@TotalCharges = @MyTotalCharges
@TotalDiscounts = @MyTotalDiscounts
@TotalPayments = @MyTotalPayments
@Balance = (@MyTotalCharges - @MyTotalDiscounts - @MyTotalPayments)