Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Equivalent of First() in MS-SQL

Posted on 1998-10-01
2
239 Views
Last Modified: 2010-03-19
I want to convert a query in Access to MS-SQL Query. The Query in Access has First() function. Is there any equivalent function in MS-SQL ?
What exactly will First() do ? Is that it will pick the first record in the query (assume the query contains group by clauses) or the first inserted record in the table ?

If i want to find the first inserted record then i want to know the equivalent of rowid as in Oracle
0
Comment
Question by:vvg
2 Comments
 

Author Comment

by:vvg
ID: 1090354
Edited text of question
0
 
LVL 1

Accepted Solution

by:
gertrude earned 30 total points
ID: 1090355
If you simply want to limit the number of rows returned from a TSQL script to 1 you can:

  SET ROWCOUNT 1   -- forces results to be limited to one record
  SELECT ......    
  SET ROWCOUNT 0   -- results will return all records

If you want to know the IDENTITY value of a record you just added to a table (assuming the table has an IDENTITY column) you can use:

  SELECT @@Identity

immediately after your INSERT statement.  Note that @@Identity is connection specific.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

861 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