Sp以获取序列中的下一个记录 [英] Sp to get the next Record in a sequence

查看:68
本文介绍了Sp以获取序列中的下一个记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



正在处理存储过程以从序列中获取下一条记录
请帮助以下脚本

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

推荐答案

尝试:
SELECT TOP 1 id, aaa, bb, cc FROM myTable WHERE id > @id ORDER BY id ASC




您可以使用

<您的序列名>
的下一个值
检查此链接,
http://msdn.microsoft.com/en-us/library/ff878058.aspx [ ^ ]
希望这会有所帮助.
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.


这篇关于Sp以获取序列中的下一个记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆