How to fetch record after/from specify value (Record/ID) in sql server

In this article, we will how to fetch record after and before specify a column in SQL server. Recently when I am creating an MLM application where I need to insert record after specify record so below I code helped me
Table (Record):-



Fetch records from specific column:
declare @id int = (select record_id from record where record_id=3)
Select * from record where record_id > = @id

Out-Put:-



Fetch records After specific column:
Declare @ID int=3;
;WITH temp_table
as
(
  select *, ROW_NUMBER() over (order by (select 0)) as recordvalue
  from record
)

select * from temp_table where recordvalue in(select recordvalue + 1 from temp_table where record_id >= @ID);



Out-Put:-


How to fetch record after/from specify value (Record/ID) in sql server How to fetch record after/from specify value (Record/ID) in sql server Reviewed by NEERAJ SRIVASTAVA on 12:29:00 PM Rating: 5

No comments:

Powered by Blogger.