Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SQL query help

Posted on 2014-12-10
2
Medium Priority
?
256 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 52

Accepted Solution

by:
Vitor Montalvão earned 1200 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 800 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

618 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