Solved

Equivalent of First() in MS-SQL

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
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…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

707 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