如何从我的存储过程中仅获取一组数据?
我正在使用 SQL Server 2000。
我的 SP 产生以下输出:
它总结了所有应税收入
(顶部结果)并减去可扣除费用
之和(中间结果)即可得到员工的应税净收入
。
我如何仅获得应税净收入的值?
这是我的SP
/*
DECLARE @NET_TAXABLE_INCOME AS NUMERIC(19, 2)
EXEC NET_TAXABLE_INCOME '000001', '10/15/2010', @NET_TAXABLE_INCOME OUTPUT
SELECT @NET_TAXABLE_INCOME
*/
CREATE PROC [dbo].NET_TAXABLE_INCOME
(
@EMPLOYEENO AS VARCHAR(10),
@PAYROLLPERIOD_INPUT AS DATETIME,
@NET_TAXABLE_INCOME AS NUMERIC(19, 2) = NULL OUTPUT
)
AS
BEGIN
DECLARE @TAXABALEEARNINGS AS NUMERIC(18, 2)
EXEC TAXABLE_EARNINGS_BREAKDOWN @EMPLOYEENO, @PAYROLLPERIOD_INPUT, @TAXABALEEARNINGS OUTPUT
DECLARE @DEDUCTIBLEEXPENSES AS NUMERIC(18, 2)
EXEC DEDUCTIBLE_EXPENSES_BREAKDOWN @EMPLOYEENO, @PAYROLLPERIOD_INPUT, @DEDUCTIBLEEXPENSES OUTPUT
SET @NET_TAXABLE_INCOME = @TAXABALEEARNINGS - @DEDUCTIBLEEXPENSES
SELECT @NET_TAXABLE_INCOME AS [NET_TAXABLE_INCOME]
END
是否有一个SQL语句会导致不打印EXEC
的结果?
I'm using SQL Server 2000.
My SP produces the follwing output:
It sums up all Taxable Earnings
(top result) and subtract it by the sum of Deductible Expenses
(middle result) to get the Net Taxable Income
of an employee.
How will I get the value of Net Taxable Income only?
Here's my SP
/*
DECLARE @NET_TAXABLE_INCOME AS NUMERIC(19, 2)
EXEC NET_TAXABLE_INCOME '000001', '10/15/2010', @NET_TAXABLE_INCOME OUTPUT
SELECT @NET_TAXABLE_INCOME
*/
CREATE PROC [dbo].NET_TAXABLE_INCOME
(
@EMPLOYEENO AS VARCHAR(10),
@PAYROLLPERIOD_INPUT AS DATETIME,
@NET_TAXABLE_INCOME AS NUMERIC(19, 2) = NULL OUTPUT
)
AS
BEGIN
DECLARE @TAXABALEEARNINGS AS NUMERIC(18, 2)
EXEC TAXABLE_EARNINGS_BREAKDOWN @EMPLOYEENO, @PAYROLLPERIOD_INPUT, @TAXABALEEARNINGS OUTPUT
DECLARE @DEDUCTIBLEEXPENSES AS NUMERIC(18, 2)
EXEC DEDUCTIBLE_EXPENSES_BREAKDOWN @EMPLOYEENO, @PAYROLLPERIOD_INPUT, @DEDUCTIBLEEXPENSES OUTPUT
SET @NET_TAXABLE_INCOME = @TAXABALEEARNINGS - @DEDUCTIBLEEXPENSES
SELECT @NET_TAXABLE_INCOME AS [NET_TAXABLE_INCOME]
END
Is there a SQL statement that will cause to not to print the result of EXEC
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 C# 方面,您可以执行以下操作:
On the C# side, you can do:
您可以将执行的存储过程的结果放入临时表中。
但您也可以将它与 EXEC 命令结合使用,这就是捕获存储过程的输出的答案。您需要做的就是创建一个表来通过 INSERT 语句接收存储过程的输出:
关键是创建表(本例中为临时表),使其具有正确的列数和兼容的数据类型捕获存储过程的输出。
注意:语法是伪语法,但我希望你明白了!
这样,您就可以丢弃这些结果 - 因为这就是您的意图,而不会影响调用存储过程的输出!
但是,如果这些存储过程在您的控制之下,您应该考虑是否真的想重用它们/更改为仅返回输出参数而不返回结果集。您不必要地返回您不会使用的数据,至少在这种情况下是这样
You can get the results of the executed Stored procedures into a Temporary table instead.
But you can also combine it with the EXEC command as well, and that's the answer to capturing the output of the stored procedure. All you need to do is create a table to receive the output of the stored procedure via the INSERT statement:
The key is to create the table (a temporary table in this example) so that it has the right number of columns and compatible data types to capture the output of the stored procedure.
NOTE: syntax is psuedo syntax but you get the idea, i hope!
That way, you can then just discard these results - as that is what your intention is without affecting the output of your calling stored procedure!!
However, if these stored procedures are under your control, you should consider if you really want to reuse them / change then to only return the output param and not the resultset. You are un-necesssarily returning data that you are not going to use, atleast in this case