Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 How To get the first data in a table?

Author  Topic 

ReLski
Starting Member

5 Posts

Posted - 2011-01-12 : 19:44:20
How To get the first data in a table using stored procedures?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-01-12 : 19:50:51
CREATE PROC SomeName
AS
SET NOCOUNT ON

SELECT TOP 1 *
FROM YourTable
ORDER BY YourSequencer DESC

GO

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-01-12 : 19:51:09
If that's not what you want, then please be more specific by posting some sample data.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-01-12 : 19:52:22
quote:
Originally posted by dataguru1971

That depends.

Select top 1 * from table

will return the 1st row..but depending on if there is a clustered index etc, it may not be the "first row".



Clustered index or not, you still need an ORDER BY.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-01-14 : 05:23:12
quote:
Originally posted by tkizer

quote:
Originally posted by dataguru1971

That depends.

Select top 1 * from table

will return the 1st row..but depending on if there is a clustered index etc, it may not be the "first row".



Clustered index or not, you still need an ORDER BY.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog


It seems the post was deleted.

I agree with you. Dont reply on default ordering. If you want data with specific order, always use ORDER BY Clause.

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -