Click here to Skip to main content
15,880,967 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
iam dynamically accessing tables from database now want to get row no with the datatable value
how can i use Row_number() function with the query
Select * from mytable
Posted

You can refer the below link

how-do-i-use-row-number[^]
 
Share this answer
 
Comments
srilekhamenon 3-Feb-14 0:23am    
Sir iam dynamically accessing the tables so i have query like Select * from table1, select * from table2 so i can not specify the column name to generate Row_number() now how can i generate Row_Number()
[no name] 3-Feb-14 0:30am    
You can check this once
http://stackoverflow.com/questions/1646657/adding-row-numbers-to-a-select-query-result-in-sql-server-without-use-row-number
Try
SQL
SELECT ROW_NUMBER()
        OVER (ORDER BY a) AS Row,
    EmployeeId, EmployeeName, Salary
FROM Employees
 
Share this answer
 
Comments
srilekhamenon 3-Feb-14 0:22am    
Sir iam dynamically accessing the tables so i have query like Select * from table1, select * from table2 so i can not specify the column name to generate Row_number() now how can i generate Row_Number()
SQL
CREATE TABLE #Temp
(
Id int Identity(1,1),
Name nvarchar(100)
)

INSERT INTO #Temp(Name) VALUES('SANDEEP'),('RAVIENDER')

SELECT Name, ROW_NUMBER() OVER(ORDER BY Name) AS ROW From #Temp

DROP TABLE #Temp
 
Share this answer
 

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