Click here to Skip to main content
15,921,531 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

am working on a store procedure to get the next record from the sequence
plz help on the below script

USE [testing]
GO
/****** Object:  StoredProcedure [dbo].[sp_get_next]   
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[sp_get_next]
		(
	
		@id int 
		)	
AS
BEGIN
	
	SET NOCOUNT ON;

    
	select id,aaa,bb,cc from TestDB 
	where id>=(select MAX(id) from TestDB where id<@id)
	order by id
END
Posted
Updated 4-Sep-12 0:31am
v2

Try:
SQL
SELECT TOP 1 id, aaa, bb, cc FROM myTable WHERE id > @id ORDER BY id ASC
 
Share this answer
 
Hi,

You can use ,

NEXT VALUE FOR <your_sequence_name>

check this link,
http://msdn.microsoft.com/en-us/library/ff878058.aspx[^]
Hope this helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900