Database Reference
In-Depth Information
Now that we know how to calculate the value of extended price, we can compare this
computed value to the stored value of ExtendedPrice by using the SQL query:
/* *** SQL-Query-CH02-36 *** */
SELECT Quantity * Price AS EP, ExtendedPrice
FROM ORDER_ITEM;
The result of this statement now allows us to visually compare the two values to ensure that
the stored data are correct:
Another use for SQL expressions in SQL statements is to perform string manipulation.
Suppose we want to combine (using the concatenation operator, which is the plus sign [ + ] in
Microsoft SQL Server 2012) the Buyer and Department columns into a single column named
Sponsor. To do this, we can use the SQL statement:
/* *** SQL-Query-CH02-37 *** */
SELECT Buyer+' in '+Department AS Sponsor
FROM SKU_DATA;
The result will include a column named Sponsor that contains the combined text values:
By The Way The concatenation operator, like many SQL syntax elements, varies from one
DBMS product to another. Oracle Database uses a double vertical bar [ ∙ ] as
the concatenation operator, and SQL -QUERY-CH02-37 is written for Oracle Database as:
/* *** SQL-Query-CH02-37-Oracle-Database *** */
SELECT Buyer || ' in ' || Department AS Sponsor
FROM
SKU_DATA;
MySQL uses the concatenation string function CONCAT() as the concatenation opera-
tor with the elements to be concatenated separated by commas with the parentheses,
and SQL-QUERY-CH02-37 is written for MySQL as:
/* *** SQL-Query-CH02-37-MySQL *** */
SELECT
CONCAT(Buyer,' in ',Department) AS Sponsor
FROM
SKU_DATA;
 
Search WWH ::




Custom Search