Solved

SQL query help

Posted on 2014-12-10
2
234 Views
Last Modified: 2014-12-10
Hello there,

I have this query and I get this error when I run it
Invalid column name 'province'.

 SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY province) AS rowID FROM (SELECT TOP 100 PERCENT  
			province.capital,
    province.code,
    province.telcode,
    province.taxcode,
    county.countyname as county,
    district.districtname as district,
    zone.alternateName as zone,
    neighbourhood.alternateName as neigbhour,
    city.cityname as city,
    city.fdocode 
			 FROM 
				province
				JOIN county ON province.Id = county.provinceId
				JOIN district ON district.countyId = county.Id
				JOIN city ON city.districtId = district.Id
				JOIN zone ON zone.cityId = city.Id
				JOIN neighbourhood ON neighbourhood.zoneId = zone.Id
				JOIN customer ON customer.neighbourhoodId = neighbourhood.Id
			 WHERE ('1'='1')) x) y WHERE y.rowID BETWEEN 1 AND 75

Open in new window

0
Comment
Question by:zolf
2 Comments
 
LVL 46

Accepted Solution

by:
Vitor Montalvão earned 300 total points
ID: 40490842
Looks like province is a table and you are using it in the ORDER BY clause.
Verify the line SELECT *, ROW_NUMBER() OVER (ORDER BY province) AS rowID and check which column should be used in the ORDER BY clause
0
 
LVL 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 200 total points
ID: 40490848
province is a table name, in the first place, so if that (or another table) also has a column name province, you need to write this in the query for the column province.province
which also brings up this article I wrote: use aliases in your queries:
http://www.experts-exchange.com/Database/Miscellaneous/A_11135-Why-should-I-use-aliases-in-my-queries.html
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now