Solved

Equivalent of First() in MS-SQL

Posted on 1998-10-01
2
237 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

809 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