Click here to Skip to main content
15,908,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
SELECT row_number() Over (Order by dbo_M_City.CityID) as [Sno],dbo_M_City.CityID, dbo_M_City.CityName
FROM dbo_M_City;



i need to get serial number used this query but it shows error
syntax error (missing operator) in query expression 'row_number() over (order by dbo_M_City.CityID)


Can any one help
Posted
Comments
gvprabu 26-Apr-13 3:36am    
u need to use "dbo." not "dbo_". When ever u are going for JOIN then we have to use table alais then also no need to use full table name and dot(.) column name.

Hi,

Some syntax problem, No need to specify every where tablename.Column name.
SQL
SELECT row_number() Over (Order by CityID) as [Sno],CityID, CityName
FROM dbo.M_City

Check the following link, You will get Clear Idea abount ROW_Number() Function.
How to use ROW_NUMBER() to enumerate and partition records in SQL Server[^]
ROW_NUMBER (Transact-SQL)[^]

Regards,
GVPrabu
 
Share this answer
 
v2
Comments
Usha Muhunthan 26-Apr-13 3:29am    
I tried Both the link. the same error happening
Maciej Los 26-Apr-13 3:36am    
+5
gvprabu 26-Apr-13 3:51am    
What error ur getting.... send the error description
Usha Muhunthan 26-Apr-13 5:56am    
error (missing operator) in query expression 'row_number() over (order by dbo_M_City.CityID)'.



My query is SELECT row_number() Over (Order by CityID) as [Sno],CityID, CityName
FROM dbo.M_City
gvprabu 26-Apr-13 6:05am    
dbo_M_City.CityID then what is this yar...?
See if u used
SELECT row_number() Over (Order by CityID) as [Sno],CityID, CityName
FROM dbo.M_City
Then where is "dbo_M_City.CityID". Check ur Query
SQL
SELECT ROW_NUMBER() OVER (ORDER BY CITYID) as [SNO],
CITYID,
CITYNAME
FROM dbo.M_CITY;


Here, I tried replicating your issue locally and this solved the problem.
 
Share this answer
 
Comments
Usha Muhunthan 26-Apr-13 5:57am    
receiving Same error

error (missing operator) in query expression 'row_number() over (order by dbo_M_City.CityID)'.
Vamshi Krishna Naidu 26-Apr-13 9:08am    
Hey usha,

Is your table name dbo_m_city? Or Or just m_city? If it is later, query from either of our solutions will work. If it's the first one, use our query and before table name put dbo. Try that and let us know.
Usha Muhunthan 29-Apr-13 0:19am    
my table name is M_City only. Now i tried with SELECT ROW_NUMBER() OVER (ORDER BY CITYID) as [SNO],CityID, CityName FROM M_City;
Receiving same error

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