Expressions


If you are the least bit familiar with programming languages, you know that expressions are anything that, when calculated, result in a value. For instance, 1 + 1 = 2 is an example of an expression. Expressions in SQL work similarly. Consider the following data that could appear in the Employees table:

EmployeeID

FirstName

LastName

1

Ada

Spada

2

Agnes

Senga

3

Cammy

Franklin

4

Dave

Terry

5

Ferris

Wheel


You could use a simple SELECT statement to display the information exactly as it appears in the preceding table, or you could write an expression that appends the FirstName and LastName fields together. The query would look like this:

 SELECT EmployeeID, FirstName & LastName AS Name FROM Employees 

Notice the & operator. The & operator is used to concatenate, or join, two fields into one virtual field using the AS keyword. The results would display as follows:

EmployeeID

Name

1

AdaSpada

2

AgnesSenga

3

CammyFranklin

4

DaveTerry

5

FerrisWheel


Notice that there is no space between the first and last names. To add a space, you need to add a literal string value as follows:

 SELECT EmployeeID, FirstName & ' ' & LastName AS Name FROM Employees 

NOTE

You might have noticed that we've been using single quotes in every SQL statement. The reason for this is simple: When you construct your SQL statements in Dreamweaver, the server-side language encloses the entire statement in double quotes. For the statement to be valid, strings within a SQL statement must be enclosed within single quotes.


Adding the space results in a gap between the first and last names as follows:

EmployeeID

Name

1

Ada Spada

2

Agnes Senga

3

Cammy Franklin

4

Dave Terry

5

Ferris Wheel





Macromedia Dreamweaver 8 Unleashed
Macromedia Dreamweaver 8 Unleashed
ISBN: 0672327600
EAN: 2147483647
Year: 2005
Pages: 237
Authors: Zak Ruvalcaba

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net