Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
table have only one column name.i have to retrieve a particular row number,like 5th,6th
Posted
Comments
Maciej Los 13-Aug-15 4:32am    
Sample data would be helpful! What you mean by saying: 5th, 6th row?

 
Share this answer
 
Hi Manish ,
try this

Solution 1:- Row_Number () function
Cons :-Row_Number sort the Column value so that u cant not retrieve exact value at that row number as it is in Original Table .

Solution 2:-
Declare @tbl (ID int Identity(1,1), ColumnVal varchar(100))
Insert into @tbl
Select ColumnName from Table --(your table with Column name )

Select columnVal from @tbl where ID=5 (Or 6 What ever u want);

Hope it helps u lot .
:)
 
Share this answer
 
v2
Comments
manish-gusain8909 13-Aug-15 8:48am    
in table i have only one column, i dont have id column.
KapilMuni 13-Aug-15 9:13am    
Dear Id column is Identity field, which is auto generated. it helps to find the nth position of data value .Still u have concern contact 7838018036
Hi Manish,
SQL
SELECT * FROM (
  SELECT
    ROW_NUMBER() OVER (ORDER BY columnname ASC) AS rownumber,
  columnname
  FROM tbl_studreg

) AS foo
WHERE rownumber =5 or rownumber = 6

DEfinitely it will work :-):-)

Improved Answer
SQL
SELECT * FROM (
  SELECT
  ROW_NUMBER() OVER (ORDER BY ID ASC) AS rownumber,
  ID
  FROM tablename

) AS foo
WHERE ID =5

For "ID" Replace ur condition column
The condition column name must be primary key
 
Share this answer
 
v6
Comments
manish-gusain8909 13-Aug-15 8:50am    
we cant have where conditions on row_number,rank() .
Arasappan 13-Aug-15 8:53am    
please clearly explain
Arasappan 13-Aug-15 9:14am    
see my improved answer.output 100% sure :-)
Arasappan 14-Aug-15 0:27am    
take the idea from the answer and modify as per ur need.. thank u

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900