Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 column alias

Author  Topic 

siumui
Yak Posting Veteran

54 Posts

Posted - 2012-03-13 : 10:09:28
Hello.

Is it possible to give a column an alias when you perform a query without using the word As?

For example:
Select Employee_Name First
from Employee

compared to
Select Employee_Name As First
from Employee

siumui

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-03-13 : 10:13:32
yes


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

siumui
Yak Posting Veteran

54 Posts

Posted - 2012-03-13 : 10:23:12
Thank you webfred.

When selecting columns and put it in new table, what does the # before the new table name means?

For example:
Select loannumber Acct, "Yes" Default
into #DefaultLoan
from ........

siumui
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-03-13 : 10:24:27
it is a temp table and will be dropped when the session on sql server ends or you drop it


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

siumui
Yak Posting Veteran

54 Posts

Posted - 2012-03-13 : 10:28:05
So for temp table, you have to use the # sign?

siumui
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-03-13 : 10:29:14
yes


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

siumui
Yak Posting Veteran

54 Posts

Posted - 2012-03-13 : 10:38:45
quote:
Originally posted by webfred

it is a temp table and will be dropped when the session on sql server ends or you drop it




Please elaborate on what do you mean by the session on sql server ends? Do you mean when the query is finish?

siumui
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-03-13 : 10:44:50
see here for more detailed information about temp tables:
http://www.sqlteam.com/article/temporary-tables


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

siumui
Yak Posting Veteran

54 Posts

Posted - 2012-03-13 : 10:50:02
Thank you very much webfred!

When selecting columns, and if there are " " quotes around the column name, does that means that column will be blank?

For example:
Select first_name, last_name, " [maiden name] ", 'No' married
into #change
from .....

the column maiden name has [ ] around it because there is a space in the column's name, correct?

the column married will be filled with a string No, correct?

siumui
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-03-13 : 10:50:27
quote:
Originally posted by siumui

quote:
Originally posted by webfred

it is a temp table and will be dropped when the session on sql server ends or you drop it




Please elaborate on what do you mean by the session on sql server ends? Do you mean when the query is finish?

siumui


If you have started your query in a query windows in SSMS then the session ends when closing the window.
A session also ends when you are closing the connection.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-03-13 : 10:55:11
quote:
Originally posted by siumui

Thank you very much webfred!

When selecting columns, and if there are " " quotes around the column name, does that means that column will be blank?
yes, but you don't need the double quotes. Better use [ and ]

For example:
Select first_name, last_name, " [maiden name] ", 'No' married
into #change
from .....

the column maiden name has [ ] around it because there is a space in the column's name, correct?
every time a column name is something special like that you need to use [ and ] but not the double quotes

the column married will be filled with a string No, correct?
yes

siumui




No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

siumui
Yak Posting Veteran

54 Posts

Posted - 2012-03-13 : 11:00:11
quote:
Originally posted by webfred

quote:
Originally posted by siumui

Thank you very much webfred!

When selecting columns, and if there are " " quotes around the column name, does that means that column will be blank?
yes, but you don't need the double quotes. Better use [ and ]
The maiden name in the select statement below, maiden name column will be filled with blank because of " " surrounding the column name, correct?

For example:
Select first_name, last_name, " [maiden name] ", 'No' married
into #change
from .....

the column maiden name has [ ] around it because there is a space in the column's name, correct?
every time a column name is something special like that you need to use [ and ] but not the double quotes

the column married will be filled with a string No, correct?
yes

siumui







siumui
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-03-13 : 11:05:29
quote:
Originally posted by siumui

quote:
Originally posted by webfred

quote:
Originally posted by siumui

Thank you very much webfred!

When selecting columns, and if there are " " quotes around the column name, does that means that column will be blank?
yes, but you don't need the double quotes. Better use [ and ]
The maiden name in the select statement below, maiden name column will be filled with blank because of " " surrounding the column name, correct?

For example:
Select first_name, last_name, " [maiden name] ", 'No' married
into #change
from .....

the column maiden name has [ ] around it because there is a space in the column's name, correct?
every time a column name is something special like that you need to use [ and ] but not the double quotes

the column married will be filled with a string No, correct?
yes

siumui







siumui


No, it means the column name in the table is: blank[maiden name]blank
btw. that's real messy.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

siumui
Yak Posting Veteran

54 Posts

Posted - 2012-03-13 : 11:12:47
Why would a person want the column name to have a blank before and after the column's name?

siumui
Go to Top of Page

siumui
Yak Posting Veteran

54 Posts

Posted - 2012-03-13 : 11:16:17
I'm sorry.
I mistyped.

It should be:
Select first_name, last_name, " [maiden name], " 'No' married
into #change
from .....

Please explain the double quotes around the column maiden name.
Thank you.


siumui
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-03-13 : 11:16:19
That's a good question.
I can't imagine
Some people act like "I'm doing it because I'm able to do it."


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-03-13 : 11:18:31
quote:
Originally posted by siumui

I'm sorry.
I mistyped.

It should be:
Select first_name, last_name, " [maiden name], " 'No' married
into #change
from .....

Please explain the double quotes around the column maiden name.
Thank you.


siumui


I think you meaned the comma outside?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

siumui
Yak Posting Veteran

54 Posts

Posted - 2012-03-13 : 11:19:51
quote:
Originally posted by webfred

quote:
Originally posted by siumui

I'm sorry.
I mistyped.

It should be:
Select first_name, last_name, " [maiden name], " 'No' married
into #change
from .....

Please explain the double quotes around the column maiden name.
Thank you.


siumui


I think you meaned the comma outside?


No, you're never too old to Yak'n'Roll if you're too young to die.



No. The codes are like that. The last double quote is after the comma.

siumui
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-03-13 : 11:20:52
anyway, the quotes here are used to have [ and ] inside the column name which isn't possible without the double quotes.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-03-13 : 11:23:13
another idea: be sure there are double quotes or just two single quotes. anyway it looks senseless...


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

siumui
Yak Posting Veteran

54 Posts

Posted - 2012-03-13 : 11:26:14
Great catch webfred!!!

It's a 2 single quotes.
Sorry:-(

Select first_name, last_name, '' [maiden name], '' 'No' married
into #change
from .....

Please help. What's a 2 single quotes means for maiden name column?

siumui
Go to Top of Page
    Next Page

- Advertisement -