You must Sign In to post a response.
  • Category: SQL Server

    Query to get 1st 1000th 2000th 3000th record till the end

    Suppose I have 10000 records . I want result such that I want 1st record then 1000th record then 2000 th record till last record in my table.

    Let me know how to write this query assuming Id as column
  • #767778
    Hi Sachin,

    Kindly utilize this below query,

    select e.RN from (select ROW_NUMBER() over (ORDER BY (select 1 ) ) RN,* from TABLENAME) e
    where e.RN in (1,iif(e.RN % 1000 = 0, e.RN,''))

    Let me know if you have any concern in this query.

    Thank you :)

  • #767780
    Hi

    Kavipriya

    your Query return 1 only. how to set this fromvalue to to value?



    hi

    sacin
    you can go through below Query,



    WITH Sales_CTE(sno,id,name)
    as
    (
    SELECT ROW_NUMBER() over(order by id asc) sno,id,name FROM [Test].[dbo].[TblTest]
    )
    select * from Sales_CTE where sno between 1 and 10


    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.


Sign In to post your comments