Solved

simple SQL 12 code error

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

740 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