Mike Eghtebas
asked on
SELECT clause identifiers...
Regular identifiers:
- OrderAmount
Irregular identifiers: <-- Q1: Is use of the word irregular correct here?
- Order Amount <-- has space
- 2ndAddress <-- starts with a number
- !TheReason <-- starts with sign other than (_, @, or #)
- TheReason! <-- it contains sign other than (_, @, or #)
- From <-- it is a T-SQL reserved word.
Q2: Are the SELECT clauses bellow correct?
SELECT "Order Amount", "2ndAddress", "!TheReason", "TheReason!", "From" FROM SomeTable
or
SELECT [Order Amount], [2ndAddress], [!TheReason], [TheReason!], [From] FROM SomeTable
- OrderAmount
Irregular identifiers: <-- Q1: Is use of the word irregular correct here?
- Order Amount <-- has space
- 2ndAddress <-- starts with a number
- !TheReason <-- starts with sign other than (_, @, or #)
- TheReason! <-- it contains sign other than (_, @, or #)
- From <-- it is a T-SQL reserved word.
Q2: Are the SELECT clauses bellow correct?
SELECT "Order Amount", "2ndAddress", "!TheReason", "TheReason!", "From" FROM SomeTable
or
SELECT [Order Amount], [2ndAddress], [!TheReason], [TheReason!], [From] FROM SomeTable
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Ah, you're right, I didn't read the delimiters part of the documentation completely :) I've just always used [ ] when needed, had never seen " " used in T-SQL.
You learn something new everyday.
You learn something new everyday.
ASKER
With emphases on the bold portions, do you think the query will run okay?
SELECT "Order Amount", "2ndAddress", "!TheReason", "TheReason!", "From" FROM SomeTable;
SELECT "Order Amount", "2ndAddress", "!TheReason", "TheReason!", "From" FROM SomeTable;
When in doubt, test it out!
In general, avoid irregular object names like the plague. They just cause more problems than they are worth, in my opinion. If not now, down the road when someone else has to deal with them.
Create table SomeTable ("Order Amount" char(2), "2ndAddress" char(2), "!TheReason" char(2),
"TheReason!" char(2), "From" char(2))
go
Command(s) completed successfully.
insert into SomeTable values ('A', 'B', 'C', 'D', 'E')
go
(1 row(s) affected)
SELECT "Order Amount", "2ndAddress", "!TheReason", "TheReason!", "From" FROM SomeTable
go
Order Amount 2ndAddress !TheReason TheReason! From
------------ ---------- ---------- ---------- ----
A B C D E
In general, avoid irregular object names like the plague. They just cause more problems than they are worth, in my opinion. If not now, down the road when someone else has to deal with them.
ASKER
I agree with you on staying away from irregular identifiers. Also, I didn't have access to SQL Server to test this. Furthermore, I had an earlier okay from you on this. I just wanted to double check it.
Thank you for the test.
Mike
Thank you for the test.
Mike
>>"I didn't have access to SQL Server to test this. "
then try http://sqlfidde.com
there is a drop down to choose dbms type; it supplies both mssql 2008 and 2012
then try http://sqlfidde.com
there is a drop down to choose dbms type; it supplies both mssql 2008 and 2012
ASKER
Is this paid service?
No. It is limited by 8000 characters of ddl including inserts. So its great for small tests but not for anything needing large amounts of data
ASKER
Thank you.
ASKER
Thanks,
Mike