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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Number of records returned in a query 1

Status
Not open for further replies.

wbodger

Programmer
Apr 23, 2007
769
US
If I have a simple query

Code:
select STUDY_CONSENT_DATE, ENTRYFLAG, STUDY_PROTOCOL_VISIT_CODE
from dbedrn316.dbo.tblBLConsent c join dbedrn316.dbo.tblPELEMENT pe
	on c.FID=pe.FORMID
where pe.DE_ID=1319
and STUDY_PARTICIPANT_ID=2065551212
and DELETEFLAG=0

and I want to have the number of records as part of the recordset before I loop thru all of the records, what do I do?

wb
 
How will you be "looping through"? The function @@ROWCOUNT returns the value but only after the query.


djj
The Lord is my shepherd (Psalm 23) - I need someone to lead me!
 
Try this...

select c.STUDY_CONSENT_DATE,
c.ENTRYFLAG,
c.STUDY_PROTOCOL_VISIT_CODE,
(Select COUNT(c.FID) as recs
from dbedrn316.dbo.tblBLConsent AS c
join dbedrn316.dbo.tblPELEMENT AS pe
on c.FID = pe.FORMID
where pe.DE_ID = 1319
and c.STUDY_PARTICIPANT_ID = 2065551212
and c.DELETEFLAG = 0
) AS recs
from dbedrn316.dbo.tblBLConsent AS c
join dbedrn316.dbo.tblPELEMENT AS pe
on c.FID = pe.FORMID
where pe.DE_ID = 1319
and c.STUDY_PARTICIPANT_ID = 2065551212
and c.DELETEFLAG = 0
 
That is what I was looking for, thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top