Incorrect Syntax Near The Keyword Desc Sql Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business desc command in sql server Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation
Incorrect Syntax Near The Keyword Order
Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Incorrect syntax near the keyword 'DESC' up vote 0 down vote favorite I'm trying to write an SQL query but when I try to save it throws me an incorrect syntax error. Here's the query: ( @top int, @bottom int ) AS SELECT * FROM (SELECT top (@bottom - @top + 1) * FROM (SELECT top (@bottom) * FROM tblPlayers INNER JOIN tblPosition ON tblPlayers.IDPosition = tblPosition.IDPosition INNER JOIN tblTeams ON tblPlayers.IDTeam = tblTeams.IDTeam ORDER BY (PPG DESC, APG DESC, RPG DESC) ) ORDER BY PPG ASC, APG ASC, RPG ASC ) ORDER BY PPG DESC, APG DESC, RPG DESC RETURN The problem is with the most inner ORDER BY. Without it's brackets it gives an incorrect syntax near the keyword 'ORDER'. With the brackets the error is incorrect syntax near the keyword 'DESC'. I'm out of ideas. The syntax seems fine to me. Thanks in advance. sql sql-server sql-order-by share|improve this question edited May 18 '14 at 13:34 Gordon Linoff 468k20140213 asked May 18 '14 at 13:30 iMax531 4211 PLease tell us what concrete database you're using - use the oracle, mysql, postgresql, sql-server tags - or specify what else you're using (SQL is just the query language - not a product). ALso - this is not a complete code snippet - is this the body of a stored procedure? Of a CTE? Please post something complete - not just a few lines out of the middle of something.... –marc_s May 18 '14 at 13:32 I added the sql-server tag because the syntax looks like SQL Server. –Gordon Linoff May 18 '14 at 13:34 add a comment| 1 Answer 1 active oldest votes up vote 0 down vote accepted Your query needs table aliases, which may be part or all of the problem. In addition, you should list the columns explicitly in the innermost subquery, because there are duplicate names: SELECT t.* FROM (SELECT top (@bo
ASP.NET Community Standup Forums Help Home/ASP.NET Forums/General ASP.NET/Getting Started/Incorrect syntax near the keyword 'DESC'. Incorrect syntax near the keyword 'DESC'. [Answered]RSS 7 replies Last post May 12, 2012 07:48 AM by sunitashirsat ‹ Previous Thread|Next Thread › Print Share Twitter Facebook Email Shortcuts Active Threads Unanswered Threads Unresolved Threads Support Options Advanced Search Reply sriramabi Contributor 2428 Points 1124 Posts Incorrect syntax near the keyword 'DESC'. May 12, 2012 06:58 AM|sriramabi|LINK i have one select query .but its showing threw error:Msg 156, Level 15, State http://stackoverflow.com/questions/23722447/incorrect-syntax-near-the-keyword-desc 1, Line 1 Incorrect syntax near the keyword 'DESC'. my query is select Top10 from Jp_JobPosting Group By AddedDate DESC what problem pls help me Reply ignatandrei All-Star 119052 Points 27460 Posts ModeratorMVP Re: Incorrect syntax near the keyword 'DESC'. May 12, 2012 07:00 AM|ignatandrei|LINK order by .NET Teacher | .NET Videos 5 minutes Reply sriramabi Contributor 2428 Points 1124 Posts http://forums.asp.net/t/1803030.aspx?+Incorrect+syntax+near+the+keyword+DESC+ Re: Incorrect syntax near the keyword 'DESC'. May 12, 2012 07:01 AM|sriramabi|LINK S i m sorry.. select Top(10) * from Jp_JobPosting order By AddedDate DESC its working well.. thank u Reply THINESH Member 98 Points 120 Posts Re: Incorrect syntax near the keyword 'DESC'. May 12, 2012 07:04 AM|THINESH|LINK SELECT TOP 10 NAME FROM EMPLOYEE_DETAILS ORDER BY SALARY DESC; OR SELECT TOP 3 PERSON FROM EVENTMASTER ORDER BY DATE DESC THIS ILL WORK T T Reply sriramabi Contributor 2428 Points 1124 Posts Re: Incorrect syntax near the keyword 'DESC'. May 12, 2012 07:09 AM|sriramabi|LINK THINESH SELECT TOP 10 NAME FROM EMPLOYEE_DETAILS ORDER BY SALARY DESC; THIS ILL WORK Hai THINESH andignatandrei ..You want mark us answer..bcas i m owner of asp.net forums........................this thread..... tack it yha its my misstack ..so i m sry... select Top(10) * from Jp_JobPosting order By AddedDate DESC its working.... Reply sunitashirsa... Member 113 Points 303 Posts Re: Incorrect syntax near the keyword 'DESC'. May 12, 2012 07:10 AM|sunitashirsat|LINK It should beselect Top10 from Jp_JobPosting order By AddedDate DESC Sunita R Shirsat Reply sriramabi Con
(2) June, 2010 (1) December, 2009 (1) November, 2009 (2) April, 2008 (1) July, 2007 (1) March, 2007 (2) February, 2007 (4) December, 2006 (1) November, 2006 (2) September, 2006 (4) August, 2006 (2) July, 2006 (2) June, 2006 (3) May, http://weblogs.sqlteam.com/BRETTK/archive/2005/04/25/4679.aspx 2006 (2) November, 2005 (1) October, 2005 (1) September, 2005 (1) August, 2005 (2) June, 2005 (8) May, 2005 (6) April, 2005 (5) February, 2005 (4) January, 2005 (5) December, 2004 (2) October, 2004 (2) September, 2004 (2) August, 2004 (1) June, 2004 (6) May, 2004 (2) April, 2004 (2) March, 2004 (2) February, 2004 (3) January, 2004 (2) October, 2003 (1) September, 2003 (1) Post Categories SQL Server (rss) DB2 (rss) Disconnected Ramblings (rss) Oracle (rss) Code Generataion incorrect syntax (rss) SQL Gimmicks (rss) Image Galleries Lost Again? SQLSki Team Misc Mountains Directions Misc It's an Enigma Wrapped up in a riddle Little Feat (rss) Radio 'Rita Ski Resort Cam List SQL Server Daily WTF (Doesn't mean World Tennis Federation) dbForums Member List SQL Express Team's BLOG SQL Server 2000 Books Online SQLTeam SQLTeam Member List << CREATE TYPE2 UNIQUE WHERE NULL INDEX | Home | TRUNCATE TABLE in DB2 >> Error = [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax incorrect syntax near near the keyword 'DESC'. bcp fails to import data near reserved word. [Doooh]Alrighty then. Thanks Tara (again) for pointing out the obvious. The resolution to this problem is the -q option. As BOL states, it sets quoted identifiers on in the context of the bcp thread. So that solves that problem, and I'm sure it's one that I won't forget. It's curious why there isn't a problem with the bcp out though.[/Doooh] BOL -q Executes the SET QUOTED_IDENTIFIERS ON statement in the connection between the bcp utility and an instance of SQL Server. Use this option to specify a database, owner, table, or view name that contains a space or a quotation mark. Enclose the entire three-part table or view name in double quotation marks (" "). Who knew? OK, probably everyone. I have never run into this before (mostly because I don't use reserve words as column names). The work around I used was to create a view. If anyone has a slicker way, or better, an explanation as to why bcp does fail, I'm all ears...or is that eyes? In any case....something for future reference so I don't have to remember it, and hopefully someone else might benefit. USE NorthwindGO SET NOCOUNT ONCREATE TABLE myTable99(Col1 int, [DESC] varchar(8000))GO INSERT INTO myTable99 (Col1, [DESC])SELECT 1, 'I' UNION ALLSELECT 2, 'Me' UNION ALLSELECT 3, 'Mine'GO SELECT * FROM myTable99 EXEC master..xp_cmdshell 'bcp Northwind.dbo.myTable99 out d:\data