Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Teaser

Status
Not open for further replies.

gmmastros

Programmer
Feb 15, 2005
14,909
US
I was just experimenting with the ParseName function and discovered something a bit unexpected. I thought I would share (but in the form of a teaser).

Without running the code, what do you expect the output to be?

Code:
[COLOR=blue]Create[/color] [COLOR=blue]Table[/color] #Temp(Data [COLOR=blue]VarChar[/color](50))

[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] #Temp [COLOR=blue]Values[/color]([COLOR=red]'Easy Answer'[/color])
[COLOR=blue]Select[/color] * [COLOR=blue]From[/color] #Temp

[COLOR=blue]Drop[/color] [COLOR=blue]Table[/color] #Temp



[COLOR=blue]Create[/color] [COLOR=blue]Table[/color] #Blah(Data [COLOR=blue]VarChar[/color](50))

[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color].   .   .  #Blah [COLOR=blue]Values[/color]([COLOR=red]'Huh?'[/color])
[COLOR=blue]Select[/color] * [COLOR=blue]From[/color] .  .  .     #Blah

[COLOR=blue]Drop[/color] [COLOR=blue]Table[/color]. #Blah



-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
hehehe, I won't spoil it, but run this

Code:
Create Table #Blah(Data VarChar(50))

Insert Into...#Blah Values('Huh?') --3 dots
Insert Into..#Blah Values('Huh What?') --2 dots
Select * From .#Blah  --  1 dot
Drop Table  #Blah --look ma, no dots

Denis The SQL Menace
--------------------
SQL Server Code,Tips and Tricks, Performance Tuning
SQLBlog.com, Google Interview Questions
 
I will guess that SQL will only look at what is after the third dot, and treat your 'table name' as if it was entered with no prefixes. Probably adding a fourth dot will cause it to break though?


[small]----signature below----[/small]
I can't compete with you physically, and you're no match for my brains.
You're that smart?
Let me put it this way. Have you ever heard of Plato, Aristotle, Socrates?
Yes.
Morons!
 
One more....
Code:
Create Table #Dots(Data VarChar(50))

Insert Into...#Dots(...................................data) Values('Huh?') --3 dots
Insert Into..#Dots(...................................data) Values('Huh, say what?') --2 dots
Select * From .#Dots -- 1 dot

Drop Table #Dots --look no dots!

Denis The SQL Menace
--------------------
SQL Server Code,Tips and Tricks, Performance Tuning
SQLBlog.com, Google Interview Questions
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top