In this article I am going to explain how to select records after a specific record/Id in sql server.
In previous article I have explained how to generate limitedrandom number and add hyphen after each 4th character in asp.net, how to checkstring is Palindrome or not using Reverse function or without reverse functionin sql server, how to set alternative color of column in column chart inasp.net chart control and how to create text file and download using asp.net.
I want to get records from a specific record or id. I have created a table Tb_Country and insert some dummy records.
Sql query to get records from specific Id:
I want to get all records from where id is 2.
declare @id int =(select id from dbo.Tb_Country where id=2)
Select * from dbo.Tb_Country where id > = @id
Sql query to get records after specific id:
I want to get all records after where id is 2.
Declare @ID int=2;
select *, ROW_NUMBER() over (order by (select 0)) as rn
select * from CTE where rn in(select rn + 1 from CTE where id >= @ID);
What do you think about this article?
If you found this article useful, please share and follow on Facebook, Twitter, Google Plus and other social media websites. To get free updates subscribe to newsletter. Please put your thoughts and feedback in comments section.