Solved

simple SQL 12 code error

Posted on 2014-04-19
3
1,042 Views
Last Modified: 2014-04-21
--Learning to code SQL, have error, don't understand why is the error. Please ----explain.Thanks
----------------------------------------------------------
USE [AdventureWorks2012]
select BusinessEntityID, Rate, NtileRanking, rank() Over(partition by NtileRanking order by Rate desc)as RankingWithinNtile
from (select BusinessEntityID, Rate,
    Ntile(4) Over (Order by Rate Desc) as NtileRanking
from HumanResources.EmployeePayHistory)



--Msg 102, Level 15, State 1, Line 5
--Incorrect syntax near ')'.
0
Comment
Question by:TickTech
  • 2
3 Comments
 
LVL 16

Accepted Solution

by:
DcpKing earned 500 total points
ID: 40010937
You forgot to give the subquery a name - simply add a letter at the very end of your query!

select	x.BusinessEntityID, 
		x.Rate, 
		x.NtileRanking, 
		rank() Over(partition by x.NtileRanking 
			order by x.Rate desc) as 'RankingWithinNtile'
from (	select	/*BusinessEntityID*/ 1 as 'BusinessEntityID', 
				Rate, 
				Ntile(4) over (Order by Rate Desc) as 'NtileRanking'
		from HumanResources.EmployeePayHistory	) x

Open in new window


I've put in the alias references to show why they're needed, but actually T-SQL will default to them.

hth

Mike
0
 

Author Comment

by:TickTech
ID: 40011587
Thank you for your help.
0
 
LVL 16

Expert Comment

by:DcpKing
ID: 40012368
My pleasure!
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Introduction Earlier I wrote an article about the new lookup functions (http://www.experts-exchange.com/A_3433.html) that ship with SQL Server 2008 R2.  In this article I’m going to show you another new feature of SSRS 2008 R2, this time in the vis…
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

813 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

14 Experts available now in Live!

Get 1:1 Help Now