SQL.SetCommandText
------------------

Sets the command text.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [SQL](component_SQL.md) | [2.6](newinversion26.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "SQL.SetCommandText"; Command; CommandText { ; CommandType } ) 

**MBS**( **"SQL.SetCommandText";** /\* Sets the command text. \*/  
**$Command**; /\* The command reference number gained with [SQL.NewCommand](SQLNewCommand.md). \*/   
**$CommandText**; /\* A string that represents command text string (an SQL statement or a stored procedure name).e.g. "SELECT \* FROM MyTable" \*/   
**$CommandType**) /\* Optional; Type of command. Can be CmdUnknown, CmdSQLStmt, CmdSQLStmtRaw or CmdStoredProc. CmdUnknown is default.e.g. "CmdSQLStmtRaw" \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| Command | The command reference number gained with [SQL.NewCommand](SQLNewCommand.md). | $Command |  |
| CommandText | A string that represents command text string (an SQL statement or a stored procedure name). | "SELECT \* FROM MyTable" |  |
| CommandType | Type of command. Can be CmdUnknown, CmdSQLStmt, CmdSQLStmtRaw or CmdStoredProc. CmdUnknown is default. | "CmdSQLStmtRaw" | Optional |

### Result

Returns "OK" or error message.

### Description

Sets the command text.  
  
Use SQL.setCommandText method to set the command text. Command text can also be set in [SQL.NewCommand](SQLNewCommand.md).  
  
It's not necessary to set a command type explicitly, because it is defined automatically in terms of command text string. But if you still have any reason to do it, use one of the following values:  
| CmdUnknown | Command type is not defined. Library will detect command type automatically when needed. |
|---|---|
| CmdSQLStmt | Command is an SQL statement. |
| CmdSQLStmtRaw | Command is an SQL statement that mustn't be interpreted by SQLAPI++. |
| CmdStoredProc | Command is a stored procedure or a function. |

  
To get command type use [SQL.CommandType](SQLCommandType.md) method.  
  
If the command is an SQL statement and it has parameters, a set of parameter objects creates implicitly.   
### See also

- [SQL.CommandText](SQLCommandText.md)
- [SQL.CommandType](SQLCommandType.md)
- [SQL.GetCommandTag](SQLGetCommandTag.md)
- [SQL.NewCommand](SQLNewCommand.md)
- [SQL.SetCommandTag](SQLSetCommandTag.md)

This function is free to use.

Created 18th August 2014 , last changed 13th January 2015

  
[SQL.SetCommandTag](SQLSetCommandTag.md) - [SQL.SetConnectionOption](SQLSetConnectionOption.md)

[HTML Version](SQLSetCommandText.shtml)