Solved

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

Posted on 1998-10-06
6
388 Views
Last Modified: 2008-01-16
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 ?

0
Comment
Question by:deebee
6 Comments
 
LVL 9

Expert Comment

by:perove
ID: 1964543
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
 

Expert Comment

by:Mamali
ID: 1964544
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
 
LVL 3

Expert Comment

by:TheAnswerMan
ID: 1964545
ARE you wanting to move the Row to the first Record... or are you just wanting the data in the first records?
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 3

Accepted Solution

by:
TheAnswerMan earned 100 total points
ID: 1964546
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
 
LVL 3

Expert Comment

by:TheAnswerMan
ID: 1964547
ARE you wanting to move the Row to the first Record... or are you just wanting the data in the first records?
0
 

Expert Comment

by:djcDave
ID: 12552146
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

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now