November 9, 2017 at 9:01 pm
Comments posted to this topic are about the item Tally Tables and Table Variables
November 10, 2017 at 1:34 am
Weird, but instructive - thank you!
November 10, 2017 at 3:25 am
Really enjoyed that one. Thanks!
November 10, 2017 at 6:10 am
The underlying problem, of course, is that CHAR() is both a data type and a function.
Add to that the fact that AS can be used in declaring the type of a variable or parameter (DECLARE @a AS INT) but NOT in the type of a column (because it's reserved for identifying a computed column), and you've got SQL that looks like it does one thing at first glance, but in fact does something completely different.
November 10, 2017 at 6:48 am
sknox - Friday, November 10, 2017 6:10 AMThe underlying problem, of course, is that CHAR() is both a data type and a function.
Add to that the fact that AS can be used in declaring the type of a variable or parameter (DECLARE @a AS INT) but NOT in the type of a column (because it's reserved for identifying a computed column), and you've got SQL that looks like it does one thing at first glance, but in fact does something completely different.
Very well stated, Sknox.
November 10, 2017 at 10:36 am
Amusing problem, but the correct answer would be "the insert attempts to specify values for a computed coulmn" which isn't any of the options available.
There is no problem whatever in inserting into a table that has computed columns unless the insert tries to specify values for one (or more) of them.
So the "correct answer" is not actually the correct answer.
Of course since none of the other answer optons mention a computed column, it's obvious which incorrect answer was intended to be the correct answer, so the incorrect correct answer issue is amusing rather than serious and shouldn't have led anyone astray. π
Tom
November 10, 2017 at 12:10 pm
What truly amazes me is the number of people that selected either of the first 2 answers. I can understand how someone might make the mistake of the last one if they don't know what a Tally table is, didn't understand the MyTally cte, and missed the AS.
--Jeff Moden
Change is inevitable... Change for the better is not.
November 10, 2017 at 12:11 pm
p.s. Cool problem, BTW.
--Jeff Moden
Change is inevitable... Change for the better is not.
November 10, 2017 at 4:33 pm
Jeff Moden - Friday, November 10, 2017 12:10 PMWhat truly amazes me is the number of people that selected either of the first 2 answers. I can understand how someone might make the mistake of the last one if they don't know what a Tally table is, didn't understand the MyTally cte, and missed the AS.
I guess the heading "Tally tables and table variables" will have made some people pick the second answer (especially as for a lot of people the only thing they "know" about table variables is that "they are a bad thing" so they'y haven't bothered to learn anything about them) but I can't imagine any way people would fall for the first one - what do they think a CTE is for heaven's sake? And the only way anyone can fall for the last one is if they don't know that INSERT automatically does any neccessary padding for fixed length strings so there's no need for replicate to do it.
Tom
November 10, 2017 at 5:29 pm
Totally missed seeing the AS.
November 11, 2017 at 4:28 am
Marcia J - Friday, November 10, 2017 5:29 PMTotally missed seeing the AS.
I saw it, but I was doing some VBA yesterday, so my brain automatically interpreted it as a data type declaration. D'oh!
November 12, 2017 at 8:21 am
Lesson for those who got this one wrong, AS in the column definition within the DDL means that it is a computed column.
π
November 12, 2017 at 10:27 am
Eirikur Eiriksson - Sunday, November 12, 2017 8:21 AMLesson for those who got this one wrong, AS in the column definition within the DDL means that it is a computed column.
π
Lesson even for those that almost got it wrong because of poor eye sight... enlarge the code and read it carefully with your glasses on. π
--Jeff Moden
Change is inevitable... Change for the better is not.
November 13, 2017 at 4:18 am
Nearly missed the AS, myself
fortunately, have just had my second cup of coffee, saw it and the only logical answer became apparent.
Nice riddle, thanks Steve
____________________________________________
Space, the final frontier? not any more...
All limits henceforth are self-imposed.
βlibera tute vulgaris exβ
November 14, 2017 at 6:45 am
Stewart "Arturius" Campbell - Monday, November 13, 2017 4:18 AMNearly missed the AS, myself
fortunately, have just had my second cup of coffee, saw it and the only logical answer became apparent.
Nice riddle, thanks Steve
I'm in the same boat at you, Stewart. I saw it, but it didn't register until reading the answers. Nice question.
Viewing 15 posts - 1 through 15 (of 16 total)
You must be logged in to reply to this topic. Login to reply