Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««1234»»»

SQL syntax Expand / Collapse
Author
Message
Posted Friday, May 28, 2010 1:59 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Friday, October 10, 2014 5:37 AM
Points: 434, Visits: 1,324
SELECT*FROM[sysobjects]ORDER BY 1desc

or even
EXEC('SELECT*FROM[sysobjects]ORDERBY1desc')

welcome to SQL golfing - omg LOL

The second thing is especialy bad, play with the order by to see why
Post #929508
Posted Friday, May 28, 2010 2:18 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Wednesday, October 9, 2013 5:08 AM
Points: 1,123, Visits: 603
Carlo Romagnano (5/28/2010)

Try this:
select*from sysobjects order by 1desc
No space in 1desc
I've seen that too before, same like this:
declare @a int set @a=1select @a
However, select1 or select@a won't work. It seems that a keyword preceded by an integer always works. I would definitely avoid using it though, it only confuses me.


Ronald Hensbergen

Help us, help yourself... Post data so we can read and use it: http://www.sqlservercentral.com/articles/Best+Practices/61537/
-------------------------------------------------------------------------
2+2=5 for significant large values of 2
Post #929517
Posted Friday, May 28, 2010 2:28 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: 2 days ago @ 1:00 AM
Points: 2,563, Visits: 2,420
[quote]
EXEC('SELECT*FROM[sysobjects]ORDERBY1desc')

In this case the "order by" clause is missing
ORDERBY1desc is the alias of [sysobjects]
Post #929520
Posted Friday, May 28, 2010 2:54 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Wednesday, October 1, 2014 12:40 AM
Points: 2,066, Visits: 370
I've seen that too before, same like this:
declare @a int set @a=1select @a
However, select1 or select@a won't work. It seems that a keyword preceded by an integer always works. I would definitely avoid using it though, it only confuses me.


agreed, it just increases confusion.

However was wondering, when SSMS executes the query, it would have to do some effort to remove spaces between the words
Post #929530
Posted Friday, May 28, 2010 4:36 AM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Friday, May 9, 2014 12:47 AM
Points: 3,448, Visits: 4,407
ziangij (5/28/2010)
However was wondering, when SSMS executes the query, it would have to do some effort to remove spaces between the words

SSMS itself does not execute queries because it is a client application. SSMS divides input text into batches, sequentially sends those batches to SQL Server, and displays received results. No spaces are added or removed while sending batches to the server. You can use SQL Server Profiler to see it.
Post #929570
Posted Friday, May 28, 2010 7:12 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Tuesday, October 7, 2014 2:36 PM
Points: 2,818, Visits: 2,565
They may all work, but they are all a crime against readability. I make a point of white space for readability just about everywhere.
Post #929650
Posted Friday, May 28, 2010 7:17 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, July 22, 2010 8:59 AM
Points: 110, Visits: 952
"A crime against readability" I'll reuse that quote soon enough.

Post #929657
Posted Friday, May 28, 2010 7:25 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Friday, February 4, 2011 7:20 AM
Points: 977, Visits: 1,499
I'm afraid I have to join the chorus in saying the question was poorly worded.

Interesting info though.


Tom Garth
Vertical Solutions

"There are three kinds of men. The one that learns by reading. The few who learn by observation. The rest of them have to pee on the electric fence for themselves." -- Will Rogers
Post #929666
Posted Friday, May 28, 2010 7:33 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Wednesday, October 15, 2014 8:10 AM
Points: 323, Visits: 1,466
malleswarareddy_m (5/27/2010)
I did not understand this question.in question it shows that to select wrong sytax.but all resturns table data without any error.then i did not found the wrong answer.so i applied three answers.got my point.


He did say "select all that apply"

So 1st you have to select all the statements that are correct, then guess the error statements?


The part about guessing the error messages, if there are any, are for extra credit

Ken
Post #929671
Posted Friday, May 28, 2010 8:45 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, July 16, 2014 11:36 PM
Points: 1, Visits: 27
All are correct
Post #929725
« Prev Topic | Next Topic »

Add to briefcase ««1234»»»

Permissions Expand / Collapse