SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


SQL syntax


SQL syntax

Author
Message
vk-kirov
vk-kirov
Hall of Fame
Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)

Group: General Forum Members
Points: 3724 Visits: 4408
Grant Fritchey (5/28/2010)
I would argue that while all three compile and run, none of them is "correct."

What do you think about the syntax of the following statements?

SELECT column1 * column2 FROM table1
SELECT column1 *column2 FROM table1
SELECT column1* column2 FROM table1
SELECT column1*column2 FROM table1



Probably only the first is correct, while others are "incorrect"? :-)
webrunner
webrunner
SSCarpal Tunnel
SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)

Group: General Forum Members
Points: 4179 Visits: 3887
Paul White NZ (5/29/2010)
Nice (but quite shocking!) question. I'm not at all embarrassed to say I got this one wrong.


Yes, Paul, thanks. I too got it wrong and am not ashamed to say so. It didn't occur to me that the first choice could be correct (as in, run without error), even if there would no doubt be a lot of criticism of the formatting from a readability standpoint.

Also, one quibble - well, more of a feature request; I suppose I should submit it to Steve as well: It seems to me that scoring the choice percents individually should be augmented, when checkboxes are presented as question choices, with the percentage of people who got the correct combination of selections correct. For example, in the current question, what percentage of people correctly picked all 3 boxes (versus how many overall picked box 1 vs box 2 vs box 3). That will give you an accurate count of who got the question wholly correct. It may be more trouble to program than it's worth, but it would be cool to see.

- webrunner

-------------------
"I love spending twice as long and working twice as hard to get half as much done!" – Nobody ever.
Ref.: http://www.adminarsenal.com/admin-arsenal-blog/powershell-how-to-write-your-first-powershell-script

"Operator! Give me the number for 911!" - Homer Simpson

"A SQL query walks into a bar and sees two tables. He walks up to them and says 'Can I join you?'"
Ref.: http://tkyte.blogspot.com/2009/02/sql-joke.html
Hugo Kornelis
Hugo Kornelis
SSChampion
SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)

Group: General Forum Members
Points: 11098 Visits: 12001
Webrunner, what you ask for is already available:

Above the percentages for the individual options is this:
Correct answers: 62% (1099)
Incorrect answers: 38% (675)
Total attempts: 1774



Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Steve Jones
Steve Jones
SSC Guru
SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)

Group: Administrators
Points: 63424 Visits: 19115
webrunner, that's a good point. I'll add that to the list, and I like the idea.

Follow me on Twitter: @way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
My Blog: www.voiceofthedba.com
UMG Developer
UMG Developer
SSCrazy
SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)

Group: General Forum Members
Points: 2706 Visits: 2204
I think I wouldn't hire anybody that wrote code like that. Using * at all is bad enough. ;-)
epriddy
epriddy
SSC Journeyman
SSC Journeyman (91 reputation)SSC Journeyman (91 reputation)SSC Journeyman (91 reputation)SSC Journeyman (91 reputation)SSC Journeyman (91 reputation)SSC Journeyman (91 reputation)SSC Journeyman (91 reputation)SSC Journeyman (91 reputation)

Group: General Forum Members
Points: 91 Visits: 110
lol! Too true! :-D
James Goodwin
James Goodwin
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1419 Visits: 1107
While I got the answer right, the explanation of the answer: "The "*" Specifies that all columns are returned, so space is not necessary in between, before, or after * in a SELECT statement" doesn't explain what is happening.

The SQL Parser is using non-alphanumeric (or, possibly, reserved) characters to determine the end of each string token. It uses non-numeric characters to determine the end of numeric tokens. Thus SELECT 1FROM <table> works, but SELECT1FROM <table> doesn't.

There was probably no decision made to allow SELECT*FROM. This is probably a result of wanting to allow mathematical formulas without forcing spaces around the operator (e.g.) field1 + 2 vs field1+2.
--
JimFive
Tom Thomson
Tom Thomson
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14402 Visits: 12213
Paul White NZ (5/29/2010)
Grant Fritchey (5/28/2010)
I would argue that while all three compile and run, none of them is "correct."

In the same way that 2+2=5 for sufficiently large values of 2? :-P

I have to agree with Grant. What does the formal syntax definition of a select statement specify? I believe it requires whitespace between the SELECT keyword and the select list. The fact that the T-SQL parser has a wiggle (don't know whether it was an intended feature or an unintended consequence of the handling of * in its multiply operator role, so call it a "wiggle" rather than a "feature or a "bug", although I think "bug" would really be more appropriate) which allows it to correct some incorrect syntax doesn't make that syntax correct, it just makes it usable. Of course I may have misinterpreted the BNF definition of the syntax - maybe someone should check me.

Tom

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search