Thank you for the reply. But this query gives only the nth record in table, but I want every Nth row (ex: 10th, 20th, 30th....) in the table. Can we do that?
Thank you for the reply. But this query gives only the nth record in table, but I want every Nth row (ex: 10th, 20th, 30th....) in the table. Can we do that?
hi,
we can do that. pass the ranks as varchar comma seperated
eg: @Rank as '10,20,30'
use the following query, it will give you the ranks you specified, if @Rank is null the will give you all the records
[code=sql]
SELECT * FROM (SELECT *,(Dense_Rank() Over (ORDER BY Column_Name DESC)) AS Rank
FROM Table_Name) AS Z
WHERE (','+isnull(@Ra nk,convert(varc har(10),Z.Rank) )+',') like
('%,'+convert(v archar(20),Z.Ra nk)+ ',%')))
Comment