Solved

simple SQL 12 code error

Posted on 2014-04-19
3
1,086 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
[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
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

738 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