December 14, 2015 at 11:30 am
SELECT T. Col1, T.col2
FROM TABLE T
WHERE 1 = 1
There is a space after T. and before Col1 without the use of brackets and yet this works for some reason. Shouldn't this space raise an error? I found it some code from a third party vendor and I'm having trouble understanding how it didn't raise an error when used.
Kindest Regards,
Just say No to Facebook!December 14, 2015 at 12:06 pm
I have never seen that but it's possible to have a column named <blank space>. Note the DDL below:
IF OBJECT_ID('tempdb..#t1') IS NOT NULL DROP TABLE #t1;
CREATE TABLE #t1 ([ ] int, col1 int, col2 int);
-- THIS:
SELECT t. Col1, t.col2
FROM #t1 t
-- IS THE SAME AS THIS:
SELECT t.[ ] AS Col1, t.col2
FROM #t1 t
This is one reason some people consider it a best practice to always us "AS" for column aliasing.
-- THIS IS NOT POSSIBLE:
SELECT t. AS Col1, t.col2
FROM #t1 t
-- Itzik Ben-Gan 2001
December 14, 2015 at 12:48 pm
Alan.B (12/14/2015)
-- THIS:
SELECT t. Col1, t.col2
FROM #t1 t
-- IS THE SAME AS THIS:
SELECT t.[ ] AS Col1, t.col2
FROM #t1 t
No it isn't. 1st one returns contents of columns Col1, Col2; 2nd returns contents of [ ], Col2
Nothing wrong with spaces (or tabs, new line feeds, etc.) between the . and the column name. Guess it gets parsed out. Wouldn't recommend it myself though.
SELECT d. database_id, d.
name
FROM sys.databases d
December 14, 2015 at 12:52 pm
YSLGuru (12/14/2015)
SELECT T. Col1, T.col2
FROM TABLE T
WHERE 1 = 1
There is a space after T. and before Col1 without the use of brackets and yet this works for some reason. Shouldn't this space raise an error? I found it some code from a third party vendor and I'm having trouble understanding how it didn't raise an error when used.
Yes, I have seen it before, and it is perfectly legal within the language syntax, as it is also legal to start a row source with just a dot and to have line breaks
use AdventureWorks2014;
select
c
.
*
from
.
Sales
.
Customer
as
c
Just don't.
MM
select geometry::STGeomFromWKB(0x0106000000020000000103000000010000000B0000001000000000000840000000000000003DD8CCCCCCCCCC0840000000000000003DD8CCCCCCCCCC08408014AE47E17AFC3F040000000000104000CDCCCCCCCCEC3F9C999999999913408014AE47E17AFC3F9C99999999991340000000000000003D0000000000001440000000000000003D000000000000144000000000000000400400000000001040000000000000F03F100000000000084000000000000000401000000000000840000000000000003D0103000000010000000B000000000000000000143D000000000000003D009E99999999B93F000000000000003D009E99999999B93F8014AE47E17AFC3F400000000000F03F00CDCCCCCCCCEC3FA06666666666FE3F8014AE47E17AFC3FA06666666666FE3F000000000000003D1800000000000040000000000000003D18000000000000400000000000000040400000000000F03F000000000000F03F000000000000143D0000000000000040000000000000143D000000000000003D, 0);
December 14, 2015 at 12:58 pm
I actually found that this works by accident. Made a typo and the code still worked. Took the space out when I found it.:-)
December 14, 2015 at 1:01 pm
<removed>... Posted twice somehow.
-- Itzik Ben-Gan 2001
December 14, 2015 at 1:03 pm
Gazareth (12/14/2015)
Alan.B (12/14/2015)
-- THIS:
SELECT t. Col1, t.col2
FROM #t1 t
-- IS THE SAME AS THIS:
SELECT t.[ ] AS Col1, t.col2
FROM #t1 t
No it isn't. 1st one returns contents of columns Col1, Col2; 2nd returns contents of [ ], Col2
Nothing wrong with spaces (or tabs, new line feeds, etc.) between the . and the column name. Guess it gets parsed out. Wouldn't recommend it myself though.
SELECT d. database_id, d.
name
FROM sys.databases d
Yep, I stand corrected. I guess I would have figured that out pretty quickly if I had included some sample data in my example.
-- Itzik Ben-Gan 2001
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply