Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to set a count(*) SQL statement = to a VB variable?

Status
Not open for further replies.

Kooda

MIS
Dec 18, 2001
26
0
0
US
I'm just trying to retrieve the value from a count(*) statement and I am stumped.

thanks
 

If you are returning the count in a record set, make sure you provide a name to reference the count column.

Select count(*) As RecCnt From Table Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
I am actually not using a recordset. This is what I have:

sql1 = "select count(*)from CMC_GRGR_GROUP where GRGR_ID = 'EP136"
MsgBox "" & sql1 & ""

BUT, this does not work.

Any suggestions?
 

All you've done is create a string and display it in a message box. You need to execute the query against the database. The manner in which you do that will depend on how you are connecting. Are you woring in VB with ADO or ODBC? What is the database? Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
We have an Sybase 11 database.

I've tried using a ADO connection but I can't get any *count* statements to work. I've heardthat it might be Sybase. So, I'm just trying to use SQL.

When using the "execute" statement, there are no records returned, right? Doesn't it just "execute" on the database?

*UPDATE*

Actually, someone helped me out.
THis is what worked:
countme.Open "select count(*)As myval from CMC_GRGR_GROUP where CICI_ID = '" & GroupID & "' ", conn, , , adCmdText
myvar = countme.Fields("myval")
MsgBox "" & myvar & ""

Thanks tlbroadbent
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top