存储过程返回值 [英] Stored procedure returning values

查看:78
本文介绍了存储过程返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



我对制作存储过程有疑问。我有一个包含一些数据的表。例如:TableX

(id_table int,

int value)



我想要的是通过SP返回两个值,第一个是计算所有记录的输入值,第二个是将所有值除以x并仅返回整数部分。这很简单,但我的难点是在同一个SP中完成所有这些并返回这两个以后在gridview中添加。



我做的第一个: COUNT(tableX.value)

第二个:COUNT(tableX.value)/ x



我想要一个完整的SP确实返回这些值一下子任何想法?

hello,

I'm in doubt to make a stored procedure. I have a table that contains some data. example: TableX
(id_table int,
int value)

what I want is through a SP return two values​​, the first is to count all the records entered values, and the second is to divide all values by x and return only the integer part. this is simple, but my difficulty is to do this all in the same SP and return these two to be added later in a gridview.

the first I do this: COUNT (tableX.value)
the second: COUNT (tableX.value) / x

I want a complete SP does return these values ​​all at once. any ideas?

推荐答案

您可以为您的存储过程输出参数。



查看此链接:

使用OUTPUT参数返回数据 [ ^ ]



例如:

You can make output paramaters to your stored procedures.

Check this link:
Returning Data by Using OUTPUT Parameters[^]

For example:
ALTER PROCEDURE dbo.YourSP
@id_table int,
@count1 OUTPUT,
@count2 OUTPUT

AS  
    DECLARE @x INT

    SET @x = 10; --you can make an input parameter for this if you want

    SET NOCOUNT ON;
    SELECT @count1 = COUNT(X.value), @count2 = COUNT(X.value) / @x
    FROM tableX as X
    WHERE table_id = @id_table;

RETURN





在C#中你可以使用如下:

输出参数修饰符(C#参考) [ ^ ]



我希望我能帮到你!



And in C# you can use as the follows:
out parameter modifier (C# Reference)[^]

I hope I could help you!


这篇关于存储过程返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆