Access First() function equivalent in MS-SQL Server.

I need to convert the First() function to work the same way
in SQL * Server. As there is no equivalent in MS-SQL Server.
We need to retrieve the records matching the condition and
select the first record in that group.
Has anybody converted the First() function to purely work with SQL Server ?

deebeeAsked:
Who is Participating?
 
TheAnswerManConnect With a Mentor Commented:
THIS WILL RETURN THE FIRST RECORD
Private Sub GetFirst(ar as recordset) as Variant
   dim x as long
   if not (ar.eof and ar.bof) then
      x = ar.bookmark
      ar.movefirst
      GetFirst= ar.GetRows(1)
      ar.bookmark = x
   end if
end Sub

You can referce it like this
poo = GetFirst(myrecordset)

the arrays variables are
poo(0,0) to poo(0,recordset.rowcount-1)

0
 
peroveCommented:
does the "TOP" SQL reserved word do the trick.

Ex:
SELECT TOP 1 from Mythable where...

(to select the firs record meeting the criteria.)

perove


0
 
MamaliCommented:
You can make a stored procedure, then insert your recordset in a temporary table. Then use a cursor to fetch and return the first record. Let me know if you need the SQL code for this stores procedure.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
TheAnswerManCommented:
ARE you wanting to move the Row to the first Record... or are you just wanting the data in the first records?
0
 
TheAnswerManCommented:
ARE you wanting to move the Row to the first Record... or are you just wanting the data in the first records?
0
 
djcDaveCommented:
When using Group By, you may still get multiple records if one of your fields has multiple values. To only select the First record of that particular field use the Min(field) as OneAndOnly. SQL Server will give you the First instance of the Field and you multiples will be hidden.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.