Solved

SQL query help

Posted on 2014-12-10
2
250 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 50

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 143

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
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 video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how the fundamental information of how to create a table.

724 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