Skip to content

Latest commit

 

History

History
35 lines (29 loc) · 2.64 KB

File metadata and controls

35 lines (29 loc) · 2.64 KB
description Step 3: Build and Execute an SQL Statement
title Step 3: Build and Execute an SQL Statement | Microsoft Docs
ms.custom
ms.date 01/19/2017
ms.prod sql
ms.prod_service connectivity
ms.reviewer
ms.technology connectivity
ms.topic conceptual
helpviewer_keywords
application process [ODBC], building and executing statements
SQL statements [ODBC], building and executing
ms.assetid 133b8bd4-a3c8-4f7e-93c5-c05283c8e96f
author David-Engel
ms.author v-daenge

Step 3: Build and Execute an SQL Statement

The third step is to build and execute an SQL statement, as shown in the following illustration. The methods used to perform this step are likely to vary tremendously. The application might prompt the user to enter an SQL statement, build an SQL statement based on user input, or use a hard-coded SQL statement. For more information, see Constructing SQL Statements.

Shows building and executing an SQL statement

If the SQL statement contains parameters, the application binds them to application variables by calling SQLBindParameter for each parameter. For more information, see Statement Parameters.

After the SQL statement is built and any parameters are bound, the statement is executed with SQLExecDirect. If the statement will be executed multiple times, it can be prepared with SQLPrepare and executed with SQLExecute. For more information, see Executing a Statement.

The application might also forgo executing an SQL statement altogether and instead call a function to return a result set containing catalog information, such as the available columns or tables. For more information, see Uses of Catalog Data.

The application's next action depends on the type of SQL statement executed.

Type of SQL statement Proceed to
SELECT or catalog function Step 4a: Fetch the Results
UPDATE, DELETE, or INSERT Step 4b: Fetch the Row Count
All other SQL statements Step 3: Build and Execute an SQL Statement (this topic) or Step 5: Commit the Transaction