Jump to content

Recieve @@ROWCOUNT and DataSet on SQL Server


judacoor

Recommended Posts

Here's the code that I've got:CREATE PROCEDURE [dbo].[sP_Proceso_Get_FindAll]AS SELECT [idProceso], [idCargo], [Entradas], [salidas], [Participantes], [idProcesoPadre], [TipoProceso] FROM [dbo].[Proceso] Select @@ROWCOUNTGO/****** Object: StoredProcedure [dbo].[sP_Proceso_Insert] Script Date: 07/06/2008 23:04:55 ******/SET ANSI_NULLS OFFGOSET QUOTED_IDENTIFIER ONGO/*So the thing is that the SP does kinda like a "select * from..." right? And it returns the dataset with the rows correctly, I even put it in an array to work with it in java.But sometimes I also need to know the number of rows in a table, so the easy way out is to use this SP to get the total of rows in the table, put them in the array in java and then use the array.lenght() method to get the number of elements on it.But this isn't optimal, so I was thinking about making a new SP with the "Select COUNT" instruction to get the number of rows.............but I noticed the "Select @@ROWCOUNT" instruction at the end of the Stored Procedure, so I tryed with SQL Server Management Studio and it returns the number of rows as well....... but I want to know ho to get this number from java if what I'm supposed to be recieving is the dataset with the objects found, not the number of rows....Please somebody help me!! Thanks a lot!

Link to comment
Share on other sites

You can't get them both at once, you can only return one recordset. Either it can contain one record with a count in it, or it can contain the records you're trying to select. But you can't get both, you can't have all of the records plus an additional record with how many other records there are. You'll want to use a count statement for that and do it separately.

Link to comment
Share on other sites

Thank you so much!And woud it be best to have a separate Stored Procedure with the "Select Count" instruction, or just stick to the one I already have ("Select") and then, when I get the ResultSet in Java just count the elements in it?

Link to comment
Share on other sites

If all you need to do is count, it would be better to use a procedure that only returns the count. If you need to get all of the records anyway and also show a count, might as well just count how many you got. But if you get all of the records just to count them it's going to waste time and memory.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...