Can I #AliasTemporaryTables AS #att?
-
Monday, February 04, 2013 4:53 PM
To the 99% of the development community more skilled in TSQL than me,
Please forgive the contrived example, but I was wondering if I can use table alias names that begin with a hash or pound symbol to help identify a column as coming from a temporary table in tempdb?
select s.FirstName , s.LastName , #cg.FinalGrade , s.ExpectedGraduationDate from Students s inner join #ComputedGrades #cg on #cg.StudentID = s.StudentID
In longer SELECT clauses, this might add a level of distinction between data coming from a database table and one coming from a temporary table in which the latter may have additional business logic applied.
I'm sure I've overlooked Microsoft documentation on this, so could you direct me to any further resources to read on the pros-cons?
Thanks
All Replies
-
Monday, February 04, 2013 5:01 PM
Yes, just don't use the pound sign in the alias.
Select t.* From #temp As t
Jose R. MCP
Code Samples- Marked As Answer by sevhn Tuesday, February 05, 2013 3:33 PM
-
Monday, February 04, 2013 5:06 PM
Try the below:
select
s.FirstName
, s.LastName
, cg.FinalGrade , s.ExpectedGraduationDate
from
Students s
inner join #ComputedGrades cg on cg.StudentID = s.StudentIDPlease use Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful.
-
Monday, February 04, 2013 5:16 PM
Using "#cg" and "cg" both work fine. If you have a moment, please give the table alias convention a try in your environment.
Is there something currently (or in the future) that makes "#cg" as a table alias something I should avoid doing?
Many thanks for your lightening fast replies.
-
Monday, February 04, 2013 5:23 PMModerator
I suggest to not use # sign for the aliases. Use the alias without such sign.For every expert, there is an equal and opposite expert. - Becker's Law
My blog- Marked As Answer by sevhn Tuesday, February 05, 2013 3:33 PM
-
Tuesday, February 05, 2013 3:30 PM
All,
Thanks for the feedback.
I'll go with the answer: The Industry says I shouldn't.
I guess this would be dangerously akin to Hungarian notation.
Cheers

