20.07.2013 Views

Beginning SQL

Beginning SQL

Beginning SQL

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 3<br />

84<br />

FullName<br />

First name is Stuart<br />

First name is William<br />

First name is Doris<br />

Likewise, you can assign more than one alias in the SELECT statement, as in the following code:<br />

SELECT LastName AS Surname, FirstName AS ChristianName<br />

FROM MemberDetails;<br />

The results of the preceding SELECT statement are as follows:<br />

Surname ChristianName<br />

Smith Katie<br />

Simons Susie<br />

Jackson John<br />

Gee Steve<br />

Jones John<br />

Jones Jenny<br />

Johnson Jack<br />

Botts Seymour<br />

Hills Jamie<br />

Dales Stuart<br />

Doors William<br />

Night Doris<br />

Finally, if you want to use an alias that contains spaces or any other characters normally not permitted<br />

for column names or aliases, then you must enclose the alias name inside square brackets, as shown in<br />

the following statement:<br />

SELECT LastName AS Surname, FirstName AS [Christian Name]<br />

FROM MemberDetails;<br />

Using this <strong>SQL</strong>, the alias Christian Name has a space, so it’s enclosed inside the square brackets.<br />

Square brackets allow you to use names for columns or aliases that contain characters not normally considered<br />

legal. For example, you would receive an error if you tried to use the alias One***Two, as in the<br />

following query:<br />

SELECT DateOfBirth AS One***Two FROM MemberDetails;

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!