Solved

simple SQL 12 code error

Posted on 2014-04-19
3
984 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
Comment Utility
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
Comment Utility
Thank you for your help.
0
 
LVL 16

Expert Comment

by:DcpKing
Comment Utility
My pleasure!
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

743 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

15 Experts available now in Live!

Get 1:1 Help Now