Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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?
Posted
Comments
BulletVictim 16-Sep-13 8:55am    
The select You want is rather Easy.
SELECT COUNT(tableX.value) AS Count,(COUNT(tableX.value)/x) AS Calculation FROM tableX
This will bring the values back in one select output
The rest of the SP you can do yourself
fasher_the_one 17-Sep-13 7:17am    
thankz BulletVictim, this help me well

1 solution

You can make output paramaters to your stored procedures.

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

For example:
SQL
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


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

I hope I could help you!
 
Share this answer
 
v5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900