Solved

Equivalent of First() in MS-SQL

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

[Webinar] Disaster Recovery and Cloud Management

Learn from Unigma and CloudBerry industry veterans which providers are best for certain use cases and how to lower cloud costs, how to grow your Managed Services practice in IaaS clouds, and how to utilize public cloud for Disaster Recovery

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS SQL Inner Join - Multiple Join Parameters 2 19
Sql query 107 27
Sql Query Datatype 2 18
sql server group by every 2hrs 5 7
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
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 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…
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.

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

22 Experts available now in Live!

Get 1:1 Help Now