SQL/MP Query Guide

HP NonStop SQL/MP Query Guide524488-003
1-1
1
Retrieving Data: How to Write
Queries
A query is a statement that requests data from a database. This section describes how
to write queries for a NonStop SQL/MP database. You can specify a query explicitly by
using interactive SELECT statements, application-embedded SELECT and CURSOR
statements, and report writer selections. You can specify a query implicitly in UPDATE,
INSERT, and DELETE statements.
A query can use either dynamic or static SQL. Ad hoc queries submitted through an
interface such as the NonStop ODBC Server and queries submitted directly through
the conversational interface (SQLCI) are likely to be dynamic. NonStop SQL/MP
prepares these queries for execution, compiles them, and executes them as soon as
they are submitted.
Host-language programs containing embedded SQL statements are likely to use static
SQL. NonStop SQL/MP compiles static SQL statements when the program is
developed, after the language compiler compiles the host-language source code. For
further information, see the Introduction to NonStop SQL/MP manual, the SQL/MP
Programming Manual for C, or the SQL/MP Programming Manual for COBOL85.
This section discusses these topics:
Using the SELECT Statement on page 1-2
Using Null Values on page 1-14
Using String Functions on page 1-15
Using the Concatenation Operator on page 1-20
Using Date-Time Columns on page 1-21
Defining Subqueries on page 1-28
Defining Predicates on page 1-30
Using CASE Expressions on page 1-43
Combining Data From More Than One Table on page 1-51
Using the UNION Operator on page 1-61
Developing Interactive Multistep Queries on page 1-65
If you are already familiar with SQL and you know how to write queries, you might want
to read only parts of this section; for example, you might want to read the subsection
that describes how to use join queries.
In general, the examples in this section are written for an interactive interface such as
SQLCI, but the same concepts can be used in programmatic queries (embedded