Solved

simple SQL 12 code error

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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

Written by Valentino Vranken. Introduction: The first step of creating a SQL Server Reporting Services (SSRS) report involves setting up a connection to the data source and programming a dataset to retrieve data from that data source.  The data…
It is helpful to note: This is a cosmetic update and is not required, but should help your reports look better for your boss.  This issue has manifested itself in SSRS version 3.0 is where I have seen this behavior in.  And this behavior is only see…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

895 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

12 Experts available now in Live!

Get 1:1 Help Now