Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ID ------ contact_id
- 1 -------- 100
- 2 -------- 100
- 3 -------- 200
- 4 -------- 100
- select top(1) ID from table_name where ID> 1 order by ID
- DECLARE @ContactId INT
- SET @ContactId = 100
- ;WITH ContactsCTE AS
- (
- SELECT ID,
- Contact_ID,
- ROW_NUMBER()OVER(ORDER BY ID) AS rn
- FROM Contacts
- WHERE Contact_Id > @ContactId
- )
- SELECT ID,
- Contact_ID
- FROM ContactsCTE
- WHERE rn = 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement