Databases Reference
In-Depth Information
semicolon is specified in the SQL standard with command statements as the
end-of-statement delimiter, but its use is optional with Microsoft SQL Server.
Different vendors vary in how they use end-of-statement delimiters. The result
of this statement is:
COMMPERCT YEARHIRE
15 2001
As is evident from this query, a qualifying condition (or search argument)
like SPNUM, being used to filter the result set by searching for the required
rows, does not have to appear in the query result. Its inclusion in the select list
is optional as long as its absence does not make the result ambiguous, confus-
ing, or meaningless.
To retrieve the entire record for salesperson 186 the statement would change
to:
SELECT * FROM SALESPERSON WHERE SPNUM=186
This gives the result:
SPNUM SPNAME COMMPERCT YEARHIRE OFFNUM
186 Adams 15 2001 1253
The “*” in the SELECT clause indicates that all columns (fields) are to be
retrieved.
Now, let's look at an example where you want a specific set of columns, but
don't limit the rows, such as: “List the salesperson number and salesperson name
of all of the salespersons.” Here, you would run:
SELECT SPNUM, SPNAME FROM SALESPERSON
This gives the result:
SPNUM SPNAME
137 Baker
186 Adams
204 Dickens
361 Carlyle
Finally, if you want to return all rows and all columns, all of the data in the
SALESPERSON table, you would run:
SELECT * FROM SALESPERSON
The result would be identical to the table shown in Figure 6-3.
6.2.3 Retrieving Other Values
When using Microsoft SQL Server, you can use SELECT to evaluate expres-
sions. These can be, for example, mathematical expressions or expressions
Search WWH ::




Custom Search