Solved

SQL query help

Posted on 2014-12-10
2
233 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 45

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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

746 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

10 Experts available now in Live!

Get 1:1 Help Now