Link to home
Start Free TrialLog in
Avatar of deebee
deebee

asked on

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 ?

Avatar of perove
perove
Flag of Norway image

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


Avatar of Mamali
Mamali

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.
ARE you wanting to move the Row to the first Record... or are you just wanting the data in the first records?
ASKER CERTIFIED SOLUTION
Avatar of TheAnswerMan
TheAnswerMan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ARE you wanting to move the Row to the first Record... or are you just wanting the data in the first records?
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.