TERADATA
TERADATA
TERADATA
COMPUTING ARCHITECTURES: There are two scalable hardwares that can processes and manages
the data
i.
ii.
TERADATA
TERADATA SERVER ARCHITECTURE: Teradata Client: A Teradata client is an application that allows you to prepare SQL
request.
There are two teradata queries submitting utilities.
i.
ii.
TERADATA
i.
Parser
ii.
Optimizer
iii.
Dispatcher
Parser: It performs the following activities when the request is received from
the client
I.
II.
III.
Dispatcher: -
MESSAGE PASSING LAYER (MPL): The message passing layer manages the dialogues between parsing
engine access module processor (AMP).
TERADATA
TERADATA
TERADATA COMPITITIVE ADVANTAGES: Scalability: This is the only RDBMS which confirms the performance
improvement by adding more hardware.
Maintenance: When you add hardware the data gets distributed automatically.
Shared Nothing Architecture: Using special software and hardware components, teradata gets the
data faster.
Unlimited Parallelism: -
Low CTO (Total Cost of Ownership): Ease of setup, maintenance, administration expansion.
TERADATA
Robust, parallel and scalable load and unload utilities such as BTEQ,
Fast load, Multi Load, T-pump and Fast Export.
ii.
Teradata Database
iii.
iv.
v.
CREATION ODBC CONNECTIONS: Start settings Control Panel Administrative Tools Data
Sources (ODBCS)
Select a system DSN
Click on add
Select a driver Teradata
Click on Finish
Enter the following details
TERADATA
TERADATA INDEXES: -
PRIMARY INDEXES: When the primary indexes for the table is well chosen the table rows
are evenly distributed across the multiple AMPs for the best performance.
The primary index is created at the time of creating table.
A primary index created on single column (or) combination of
columns.
There are two types of primary indexes,
I.
II.
Note: - Changing the choice of the primary index requires dropping and
recreating the table.
, COL C_INTEGER)
Unique Primary Index (COL_B);
A unique primary index results in distributing the roes very uniform.
TERADATA
TERADATA
TERADATA
SQL-SUB COMPONENTS: DATA DEFINTION LANGUAGE (DDL): The DDL allows the users to define the database objects and create
relationship among database objects. (Tables, Views, Triggers, Procedures,
Macros)
DROP
ALTER
Function
It defines a database object
(Tables, Views, Procedures, Macros,
Triggers (or) Stored Procedure).
It removes a Tables, Views,
Procedures, Macros, Triggers (or)
Stored Procedure.
It changes a database object
definition
DATA MANIPULATION LANGUAGE (DML): The DML consists of a statement that lets the user to insert, update
and delete the data rows of database.
If DDL defines the database the DML lets the user change the
information contained in the database.
10
TERADATA
It lets the user to select the data rows from one (or) more tables.
11
TERADATA
PERM Space
II.
SPOOL Space
III.
TEMP Space
12
TERADATA
Procedure: -
13
Click on OK
DEPT (Teradata)
Creation of Pass through Mapping
Creation of writer connection using ODBC
TERADATA
EMP (Teradata)
14
From Properties
Attribute
Value
Click on APPLY
Click on OK
CONSTRAINTS: -
If the given values satisfy the condition the database will accept the
record else it gets rejected. Teradata supports the following constraints
I.
Not Null
II.
Unique
III.
Primary key
IV.
Check
V.
TERADATA
Constraints are the Conditions (or) Business Rule defines on one (or)
more attributes to variable the values given by the user.
ENAME
SAL
7489
800
7369
SMITH
800
15
TERADATA
16
TERADATA
17
TERADATA
18
FOREIGN KEY: -
TERADATA
19
Unless child record is not deleted (or) inserted master record is not going
to delete (or) insert.
II.
Left-Outer Join
III.
Right-Outer Join
IV.
Full-Outer Join
V.
Cross Join
VI.
Cartesian Join
VII.
VIII.
TERADATA
The each row in the answer set contains data from columns of more
than one table.
INNER JOIN: It combines the data records from multiple tables based on Equality
Match.
An Inner Join represents the intersection of the two sets based on
common set of values called Join values.
Non ANSI Syntax: Select EMP.EMPNO, EMP.ENAME, EMP.JOB, EMP.SAL, EMP.DEPTNO,
EMP.DNAME, DEPT.LOC from EMP, DEPT where
EMP.DEPTNO=DEPT.DEPTNO
ANSI Syntax: -
20
EMPNO
1245
1389
ENAME
JOB
SAL
DEPTN
O
SIVA
CLERK
5000
10
DEPTN
O
NARAYANA
MANAGE
R
8000
20
10
SALES
HYD
20
ACCOUNT
S
BAN
30
MARKET
CHE
40
OPERATIO
NS
MU
M
1429
SURYA
CLERK
5000
30
1587
NANI
CLERK
5000
50
DNAME
LOC
TERADATA
EMP DETAILS
DEPT DETAILS
ENAME
JOB
SAL
DEPTNO
DNAME
LOC
1245
SIVA
CLERK
5000
10
SALES
HYD
1389
NARAYAN
A
MANAGE
R
8000
20
ACCOUN
TS
BAN
1429
SURYA
CLERK
5000
30
MARKET
CHE
OUTER JOIN: An Outer Join forces to combine the records even though there is no
Equality Match.
As a result an Outer Join can produce more number of records than
Inner Join.
Formulae: Outer Join= Inner Join + Non-Matching Records
LEFT OUTER JOIN: A Left Outer Join returns Inner Join rows and non-matching rows from
Left table.
21
EMPNO
ENAME
JOB
SAL
DEPTNO
DNAME
LOC
1245
SIVA
CLERK
5000
10
SALES
HYD
1389
NARAYAN
A
MANAGE
R
8000
20
ACCOUN
TS
BAN
1429
SURYA
CLERK
5000
30
MARKET
CHE
1587
NANI
CLERK
5000
50
NULL
NULL
TERADATA
EX: -
RIGHT OUTER JOIN: A Right Outer Join returns Inner Join rows and non-matching rows
from Left table.
ANSI Syntax: Select E.EMPNO, E.ENAME, E.JOB, E.SAL, E.DEPTNO, D.DNAME,
D.LOC from EMP E RIGHT OUTER JOIN DEPT D on
EMP.DEPTNO=DEPT.DEPTNO
EX: EMPNO
ENAME
JOB
SAL
DEPTNO
DNAME
LOC
1245
SIVA
CLERK
5000
10
SALES
HYD
1389
NARAYAN
A
MANAGE
R
8000
20
ACCOUNT
S
BAN
1429
SURYA
CLERK
5000
30
MARKET
CHE
NULL
NULL
NULL
NULL
40
OPERATIO
NS
MUM
FULL OUTER JOIN: A Full Outer Join returns non-matching rows from both tables.
ANSI Syntax: -
22
EMPNO
ENAME
JOB
SAL
DEPTNO
DNAME
LOC
1245
SIVA
CLERK
5000
10
SALES
HYD
1389
NARAYAN
A
MANAGE
R
8000
20
ACCOUNT
S
BAN
1429
SURYA
CLERK
5000
30
MARKET
CHE
1587
NANI
CLERK
5000
50
NULL
NULL
NULL
NULL
NULL
NULL
40
OPERATIO
NS
MUM
TERADATA
EX: -
JOINS USING ALIAS: An Alias is: A temporary name for a table (or) view
Defined in the FROM clause
Useful for abbreviating long table names
Required to join a table to itself
23
TERADATA
ACCIDENTAL CARTESIAN PRODUCTS: A Cartesian product results from an Inner Join with improper
aliasing.
Improper Join condition in a Join can result Accidental Cartesian Join.
Non-ANSI Syntax: Select EMP.EMPNO, E.ENAME, E.JOB, E.SAL, E.DEPTNO, D.DNAME,
D.LOC from EMP E FULL INNER JOIN DEPT D on
EMP.DEPTNO=DEPT.DEPTNO
Select E.EMPNO, E.ENAME, E.JOB, E.SAL, E.DEPTNO, D.DNAME,
D.LOC from EMP E FULL INNER JOIN DEPT D on 3=3
INNER JOIN ON MULTIPLE TABLES: A Join can have up to 64 participating tables (or) views.
The number of participating tables (or) views determines the
number of require Join conditions.
An n-table Join requires n-1 Join conditions.
Omitting a Join condition will result in a Cartesian product Join.
24
SELF JOIN: A Join which is made on the same table is known as Self Join.
A Self Join is also known as Recursive relationship.
EX: Each Employee has a manager, who is also an Employee
Syntax: -
, E.ENAME AS EMP_NAME
, M.MGR AS MANAGER_NUMBER
, M.ENAME AS MANAGER_NAME
TERADATA
SET OPERATORS: The following key words are available as ANSI standard set
operators
I.
UNION
II.
UNION ALL
III.
INTERSECT
IV.
UNION: The Union operator allows combining the two data sets into a single
answer set.
The Union set operator eliminates duplicates.
Syntax: SELECT * FROM EMP UNION SELECT * FROM EMP;
25
INTERSECT: -
TERADATA
EXCEPT: The Except operator produces the difference in contents of the two
sets
Syntax: CREATE a Table EMP1 as (SELECT * FROM EMP WHERE DEPTNO=20)
WITH DATA;
SELECT * FROM EMP EXCEPT SELECT * FROM EMP1;
26
Syntax: i)
ii)
Thumb Rule: If the select statement contains aggregates, other than aggregates
appears in Group By clause.
iii)
TERADATA
Some of Conditions without using Sub-Query: SELECT * FROM EMP WHERE ENAME=JONES
SELECT * FROM EMP WHERE SAL>2975 {request for finding sal >
JONES in the table}
SELECT T1.EMPNO, T1.ENAME, T1.JOB, T1.SAL, T1.DEPTNO FROM
EMP T1, EMP T2 WHERE T2.ENAME=JONES AND T1.SAL>T2.SAL
SELECT T1 * FROM EMP T1, EMP T2 WHERE T2.ENAME=JONES AND
T1.SAL>T2.SAL
Insert into EMP values (7935, JONES, MANGER, 7839,
17/07/2011, 2000, NULL, 20)
27
CONCEPT OF SUB-QUERY: When a query is dependent on the output of another query for its
predicate (condition) then we use the Sub-queries.
TERADATA
28
TERADATA
Write a query to find the list of all the employees from DEPTNO=20
whose salary is greater than any one of the salary from the
DEPTNO=30?
VIEWS: A view is like a window into one (or) more tables. It provides
customized access to base tables by,
Restricting which columns are visible from base tables
Restricting which rows are visible from base tables
Combining columns and rows from several base tables
29
TERADATA
30
TERADATA
Syntax: -
Aggregate Views: Aggregate views are views which contain aggregate expressions (or)
derived columns (scrubbing).
Aggregate and derived columns in the views must be assigned
names (Aliases).
Syntax: CREATE VIEW V_AGGR AS SELECT DEPTNO, SUM (SAL) AS SUMSAL,
AVG (SAL) AS AVGSAL FROM EMP GROUP BY DEPTNO
Join on Views: -
31
TERADATA
ANSI Syntax: -
32
TERADATA
Suggestions: o Create Views to insure that all users access to tables is via Views.
o Create Views which do complex joins (or) Aggregations to simplify
end user coding requirements.
o Use access locks when creating views to maximize data availability
to users.
SUB QUERIES: A query which is defined within the main query is known as sub
query.
The sub queries are created to simplify the long list values.
There are two types of sub queries
I.
II.
Traditional sub queries: Traditional sub queries are read from the bottom up. The lowest
level query is resolved and the results are fed to the next level of query.
A source statement may reference up to 64 tables (or) Views, thus
there may be up to 64 levels of sub query.
33
TERADATA
Sub query with WHERE Clause: SELECT EMPNO, ENAME, JOB, SAL, DEPTNO FROM EMP WHERE
DEPTNO = (SELECT DEPTNO FROM EMP WHERE ENAME = MILLER)
Sub query with Qualifier ANY: SELECT EMPNO, ENAME, JOB, SAL, DEPTNO FROM EMP WHERE SAL
> ANY (SELECT SAL FROM EMP WHERE DEPTNO=20)
The teradata server evaluates all the values which are written by
the sub query.
Sub query with Qualifier SOME: It picks up the lowest value from list of values written by the sub
query.
SELECT EMPNO, ENAME, JOB, SAL, DEPTNO FROM EMP WHERE SAL
> SOME (SELECT SAL FROM EMP WHERE DEPTNO=20)
34
Correlated Sub queries: Correlated sub queries are processed differently from traditional sub
queries.
Correlated sub queries expand the functionality of traditional sub
queries.
Correlated sub queries are processed using top down approach.
Each row of the outer query is selected and compared to the criteria
in the sub query.
Usually correlated sub query is sub query whose outer query results
are processed as against sub query result.
The sub query result is analyzed for each row of outer query.
TERADATA
When the row matches with the inner query than outer query
returns the row.
Ex: - Find the employees with the highest salary in each department
SELECT EMPNO, ENAME, JOB, SAL, DEPTNO FROM EMP EE WHERE
SAL = (SELECT MAX (SAL) FROM EMP EM WHERE EE DEPTNO= EM
DEPTNO)
Note: - correlated sub queries uses shared spool technique to which
makes them correlated sub queries are more fast and efficient.
HELP Utilities: Teradata SQL contains extensions beyond ANSI stand SQL.
There are many tools available to provide the Help for a teradata
user (or) programmer.
HELP - Command: The HELP command provides the help for any defined teradata
database object
HELP TABLE
HELP VIEW
HELP MACRO
HELP COLUMN
HELP PROCEDURE etc
SHOW Command: -
35
COMMAND
RETURNS
SHOW PROCEDURE
PROCEDURENAME
TERADATA
EXPLAIN Command: Use an EXPLAIN command to provide query execution plan which is
prepared by optimizer.
Syntax: -
Teradata Logical and Conditional Operators: Logical Operators: AND, OR, BETWEEN AND are known as logical operators to defines
the conditions in WHERE Clause.
The multiple conditions can be combined using logical operators.
AND Syntax: SELECT EMPNO, SAL, JOB, DEPTNO FROM EMP WHERE SAL > 2000
AND DEPTNO = 30
OR Syntax: SELECT EMPNO, SAL, JOB, DEPTNO FROM EMP WHERE SAL > 2000
OR DEPTNO = 30
36
Conditional Operators: -
TERADATA
ISNULL: -
IS NOT NULL Syntax: SELECT EMPNO, SAL, JOB, DEPTNO FROM EMP WHERE COMM IS NOT
NULL
IN Operator: SELECT EMPNO, SAL, JOB, DEPTNO FROM EMP WHERE DEPTNO IN
(10, 20)
IN NOT NULL: SELECT EMPNO, SAL, JOB, DEPTNO FROM EMP WHERE DEPTNO NOT
IN (20, 30)
LIKE Operator: SELECT EMPNO, SAL, JOB, DEPTNO FROM EMP WHERE ENAME LIKE
S%
Teradata SQL Extensions Date Arithmetics: The current date and time can be displayed with the following
extensions
SELECT DATE
SELECT CURRENT_DATE
SELECT TIME
37
SELECT CURRENT_TIME
SELECT CURRENT_TIMESTAMP (displays both date & time)
Date Arithmetic: Syntax: SELECT EMPNO, ENAME, SAL, JOB, DEPTNO, HIREDATE,
(DATE_HIREDATE)/365 AS EXP FROM EMP
Date Extracts: -
TERADATA
Extract is a function
DATE Arithmetic in WHERE Clause: o Displays employees experience greater than 26 years
SELECT EMPNO, ENAME, SAL, JOB, DEPTNO, (DATE_HIREDATE)/365
AS EXPERIENCE FROM EMP WHERE (DATE_HIREDATE)/365 >= 26
String Functions: String Operator: Pipe is a concatenate operator which puts two string together
Syntax: - SELECT ENAME || , || ENAME AS EMPLOYEE FROM EMP WHERE
DEPTNO=20
Sub String Function: It returns the part of the string from character string
Syntax: SELECT EMPNO, ENAME, SAL, DEPTNO FROM EMP WHERE SUBSTR
(ENAME, 1, 1) = S
38
Note: We can use string literals in a sub string function to return the part
of the string.
Syntaxes: SELECT SUBSTR (CATALOG, 5, 3)
SELECT SUBSTRING (CATALOG FROM 5 FOR 3)
Character Function: -
Syntax: SELECT EMPNO, ENAME, SAL, JOB, DEPTNO FROM EMP WHERE CHAR
(ENAME) >= 5
TERADATA
TRIM Function: It removes the spaces (or) blanks from the both sides of the string
Syntax: SELECT EMPNO, ENAME, SAL, JOB, DEPTNO FROM EMP WHERE CHAR
(TRIM (ENAME)) >= 6
SQL Assistant
II.
BTEQ
39
ii)
Execute Macro Name: Executes the SQL statements within the Macro
iii)
Show macro: -
TERADATA
40
TERADATA
iii)
41
CREATE MACRO NEW SALE (BOOKNUM SMALL INT, SDATE DATE, QTY
SMALLINT)AS (SELECT :BOOKNUM (TITLE BOOK), :SDATE (TITLE DATE,
FORMAT MMMBDDBYYYY), QTY (TITLE NBR SOLD) FROM
BOOK_SALES_HISTROY;
INSERT INTO BOOK_SALES_HISTORY (BOOK_NUMBER, SALES_DATE,
SALES_QUANTITY) VALUES (: BOOKNUM, :SDATE, :QTY););
EXEC NEWSALE (123, 20000130, 6);
TERADATA
Sample Macro: -
Create a Macro to Preserve Integrity: CREATE TABLE EMP TEST (EMP_ID INTEGER NOT NULL, NAME
VARCHAR (10), SAL DECIMAL (7, 2), DNO INTEGER, CONSTRAINT CHECK
(SAL>1000 AND DNO BETWEEN 10 AND 40) ;);
SHOW TABLE EMP TEST;
CREATE A MACRO NEW_EMPLYEE (ENO INTEGER, NAME VARCHAR
(10), SAL DECIMAL (7, 2), DNO INTEGER)
AS (ROLLBACK WORK INVALID SALARY WHERE :SAL<=1000;
ROLLBACK WORK INVALID DEPARTMENT NUMBER WHERE
:DNO>40;
INSERT INTO EMP TEST (EMP_ID, NAME, SAL, DNO) VALUES (:ENO,
:NAME, :SAL, :DNO) ;);
42
SQL statements in the BTEQ scripts do not have begin period and
have trialing semi colon.
Interactive Utility: -
TERADATA
Batch Utility: -
43
TERADATA
Exporting data: Use .EXPORT command to export the data from Teradata database
to host file.
BTEQ Report Writer: Send query result to the file in the field format.
.LOGON 127.0.0.1/TDUSER, TDUSER;
Database Sales;
.Export Report File C:\BTEQ\EMP.txt
Select EMPNO, ENAME, JOB, SAL, DEPTNO from EMP
44
.EXPORT RESET;
.QUIT;
.EXPORT RESET
.QUIT
TERADATA
Importing the Data: It imports the data from Teradata host to database (loading).
45
Causes BTEQ to read records from the file until end of fill (eof).
Procedure: Define the Input data file
.LOGON 127.0.0.1/TDUSER, TDUSER;
Database Sales
.Import Variant , file = C:\BTEQ\EMP.txt
Using
EMP_ID (Integer)
EMP_NAME (Varchar (10))
TERADATA
.Report *
BTEQ Teradata Extensions: WITH, WITHBY are Teradata extensions to ANSI standard SQL.
WITH: - It is used to produce grand totals for all the records.
WITHBY: - It is used to generate sub totals for each group.
WITH, WITHBY clauses are supported only in BTEQ does not
supported by SQL assistance.
WITHBY Syntax: - SELECT EMPNO, ENAME, JOB, SAL, DEPTNO FROM
SALES.EMP WITH SUM (SAL) BY DEPTNO
Output: -
46
TERADATA
Syntax for GRAND TOTAL: SELECT EMPNO, ENAME, JOB, SAL, DEPTNO FROM SALES.EMP WITH
SUM (SAL) (TITLE GRAND TOTAL) ORDER BY EMPNO
Output: -
WITH, WITHBY and ORDER BY: SELECT EMPNO, ENAME, JOB, SAL, DEPTNO FROM SALES.EMP WITH
SUM (SAL) BY DEPTNO WITH SUM (SAL) (TITLE GRAND TOTAL) ORDER BY
DEPTNO
INTERMEDIATE TABLES (INTERIM TABLES): Interim tables are permanent tables that are used to produce
aggregates if those aggregates are used to further computations. Such as
showing the difference between each Salary and Average Salary.
Interim tables must be created Populated, Queried and Detected by
the user when no longer needed.
47
When the table is dropped all such entries in the data dictionary
must be cleared and permanent space returns to the available unused
location.
Syntax: -
TERADATA
Once the definition of tables has been written to the data dictionary
access rights for the table must also be written to the approximate
dictionary tables.
DERIVED TABLES: A Derived table is a named temporary table obtained from sub
query.
A Derived table allows you to directly access the derived results in
other parts of overall SQL statements.
Derived tables allow the user benefits of Interim tables but within
the syntax of single SQL statements.
Conceptually the approach is same of for four separate SQL
statements it may be achieved in single SQL statements.
Derived tables are temporary tables that are created and dropped in
part of query.
They permits the use of aggregates in WHERE clause
48
OUTPUT ATTRIBUTES: Output attributes defines and alias name for columns. The following
are known as Output attributes AS, TITLE and NAMED.
AS: -
NAMED: SELECT EMPNO, ENAME, JOB, SAL, SAL*0.15 (NAMED TAX), DEPTNO
FROM EMP ORDER BY TAX
TERADATA
Title
ii)
Named
OLAP FUNCTIONS: RANK: a) Simple Ranking: SELECT EMPNO, ENAME, JOB, SAL, DEPTNO, RANK () OVER
(ORDER BY SAL DESC) AS RANKING FROM EMP QUALIFY RANKING
<=3
b) Dense Ranking: SELECT EMPNO, ENAME, JOB, SAL, DEPTNO, RANK () OVER
(PARTITION BY DEPTNO ORDER BY SAL DESC) AS RANKING FROM
EMP QUALIFY RANKING <=3
SAMPLE: -
49
Record mode
ii)
Percent mode
Syntax: SELECT EMPNO, ENAME, JOB, SAL, DEPTNO FROM EMP SAMPLE 5
SELECT EMPNO, ENAME, JOB, SAL, DEPTNO FROM EMP SAMPLE 0.25
SQL FUNCTIONS: -
TERADATA
RUNNING TOTALS: -
NULLIF Statement: The NULLIF statement an ANSI standard function which provides a
method for substituting nulls for a prescribed value.
Because NULLIF uses CASE logic it is generally advisable to rename
the column (s) being output so as to avoid the default title applied by the
CASE statement.
NULLIF for Division: If a division expression involving a denominator equal to zero and
divide by zero error will be returned.
If a denominator equals the NULL values then the result is also a
NULL and no error is generated.
The NULLIF expression can be used to connect possible zero value
denominator to a NULL value, thus preventing the divide by zero error.
NULLIF Syntax: SELECT EMPNO, ENAME, JOB, SAL, NULLIF (COMM, 0) AS COMM,
DEPTNO FROM EMP
ZERO NULLIF: -
50
TERADATA
Syntaxes: -
VOLATILE TEMPORARY TABLE: Volatile table have much in common with derived tables.
There are materialized in spool space are unknown to the data
dictionary.
Unlike derived tables, volatile tables may be used repeatedly
throughout the session.
They may be dropped at any time manually (or) automatically at the
session end.
Volatile tables required their own CREATE syntax.
The table definition is kept in cache (spool space) and not
permanently written to disk.
Volatile tables do not survive a system restart.
Syntax: Create Volatile Table VT_DEPTSAL (
51
DEPTNO INTEGER
SUMSAL DECIMAL (7, 2)
AVGSAL DECIMAL (7, 2)
MINSAL DECIMAL (7, 2)) ON COMMIT PRESERVE ROWS
INSERT INTO VT_DEPTSAL SELECT DEPTNO, SUM (SAL), AVG (SAL),
MIN (SAL) FROM EMP GROUP BY 1
TERADATA
GLOBAL TEMPORARY TABLES: Global temporary tables unlike volatile and derived tables have a
definition stored in the data dictionary.
The table itself is materialized by the first SQL DML statement which
accesses the table.
Typically an INSERT SELECT (or) an INSERT.
Like volatile, global temporary tables are local to a session.
The table instance may be dropped explicitly (or) it will be
automatically dropped at the end of the session.
A special type of space called temporary space is used for global
temporary tables.
Like perm space, temporary space is sustained during a system
restart.
Global temporary tables are thus able to survive a system restart.
52
TERADATA
DEPTNO INTEGER,
CASE EXPRESSIONS: CASE Statement: The CASE statement is used to return alternate values based on
search conditions.
There are two forms of the CASE statements,
-
Valued
Searched
53
The CASE statement will in many cases reduce the need for Interim
(or) Temporary tables and also the need to write special logic within client
applications (or) stored procedures.
First match return a result for that row.
Syntax: -
TERADATA
Searched CASE Statement: The searched CASE statement is an alternative format which allows
greater flexibility in CASE statement.
Instead of testing on a single column (or) expression, this format
allows for testing on multiple conditions each of which can involve
54
different Columns (or) Expressions. If may not also test for conditions
other than equality.
In a searched CASE statement you do not specify expression to test.
You may specify multiple, arbitrary, search conditions that can returns
different results.
CASE
WHEN SAL<1000
TERADATA
SELECT ENAME,
THEN UNDER 1K
WHEN SAL<2000
THEN UNDER 2K
WHEN SAL<3000
THEN UNDER 3K
ELSE >=4K
END
FROM EMP ORDER BY SAL
55