Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 [Resolved] Problems getting record count

Author  Topic 

snufse
Constraint Violating Yak Guru

469 Posts

Posted - 2009-09-11 : 13:05:23
Code behind:

mySqlCommand.Parameters.Add(New Data.SqlClient.SqlParameter("@RecordCount", Data.SqlDbType.Int))
mySqlCommand.Parameters("@RecordCount").Direction = Data.ParameterDirection.Output
mySqlCommand.CommandType = Data.CommandType.StoredProcedure
mySqlCommand.CommandText = ("sp_ZyTax_Get_Record_Count_jTable")
mySqlCommand.Connection = mySqlConnection
mySqlCommand.ExecuteScalar()
Return myRecordCount = mySqlCommand.Parameters("@RecordCount").Value


Stored Procedure:

@RecordCount int output

as

BEGIN
set nocount on
select count(*) from ZyTax.dbo.jTable
set @RecordCount = @@ROWCOUNT
END
GO

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-09-11 : 13:23:03
@RecordCount will always be 1. Because the @@rowcount for "select count(*) from jTable" will be 1.

Perhaps you want:

select @RecordCount = count(*) from ZyTax.dbo.jTable


Be One with the Optimizer
TG
Go to Top of Page

snufse
Constraint Violating Yak Guru

469 Posts

Posted - 2009-09-11 : 13:41:48
Did like this:

@RecordCount int output

as

BEGIN
set nocount on
declare @Records as int
select @Records = count(*) from ZyTax.dbo.jTable
set @RecordCount = @Records
END


Value of @RecordCount in the query is 5734, but it is not passed back to the program. Any idea?
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-09-11 : 13:51:42
Try this. If it works then the problem is with your application code. If that is the case you'll have to post this in the appropriate forum.

declare @myRowcount int
exec sp_ZyTax_Get_Record_Count_jTable @RecordCount = @myRowcount output
select @myRowcount [@myRowcount_out]


EDIT:
run this in a query window

Be One with the Optimizer
TG
Go to Top of Page

snufse
Constraint Violating Yak Guru

469 Posts

Posted - 2009-09-11 : 13:58:05
Yes, it works, I get a count of 5764 which is correct. I will post to another forum. Thank you for your help.
Go to Top of Page
   

- Advertisement -