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
 Other Forums
 MS Access
 Help with TOP 1 select statement??

Author  Topic 

MikeB
Constraint Violating Yak Guru

387 Posts

Posted - 2001-12-06 : 21:16:58
Here is the statement. It is returning all 6 records. Any idea what I am doing wrong?

CString csQuery = _T("");
csQuery.Format("SELECT TOP 1 * FROM Component_Sched_Tbl WHERE project_id = '%s' AND component_id = '%s' AND component_in_pour = False AND component_issued_date IS NOT NULL ORDER BY component_issued_date DESC",
csProjectID, csID);

if(m_recToCtrl.OpenRecordset(csQuery))
{
int nCount = m_recToCtrl.GetRecordCount();
if(m_recToCtrl.SetFieldValue(_T("component_in_pour"), true))
{
//Success!!
}

nCount should be equal to 1 since I am asking to select the TOP 1 but it is equal to all the records that meet the "AND" requirements.

Any ideas?
Mike B

LarsG
Constraint Violating Yak Guru

284 Posts

Posted - 2001-12-07 : 04:30:02
TOP 1 will retrieve all ties, with respect to the column in the order by clause.

Go to Top of Page
   

- Advertisement -