SQLColumnAdd - cDbUpdateFunctionLibrary

Adds a column to a SQL table.


Type: Function


Parameters: Integer hTable, String sColumnName, Integer iDataType, Integer iLength

Parameter

Description

hTable

A file handle to the table name. Same as the Filelist.cfg slot number. Note: If instead need to pass the table name as a string you can use the SQLColumnAddByTableName function.

sColumnName

The new column name to be added

iDataType

Any of the SQL data types. See SQL Server Type Mappings

iLength

Optional. The length of the column. Only applicable for some field types like e.g. SQL_VarChar.

iDecimals

Optional. The precision of the column, aka number of decimals. Only applicable for some field types like e.g. SQL_Numeric or SQL_Decimal.

bInitValue

Boolean. Pass True and also pass the sColumnValue to populate the column's existing rows with.

sColumnValue

(Optional) Only necessary if the bInitValue is passed as True. This is the value that each row in the table should be initialized with, when the new column is created.


Syntax


Function SQLColumnAdd Handle hTable String sNewColumnName Integer iDataType Integer iLength Boolean bInitValue String sColumnValue

Call:

Get SQLColumnAdd 0 MyTableName.File_Number "NewColumn" SQL_VarChar 30 0 True "NewColValue"



Description

Use it to create or add a new column to a table. The iDataType can be any of the SQL data types defined in DataFlex. The iLength and iDecimals parameter are optional, unless a data type that are not "fixed" in length is passed.

Note: If you want to add a field/column with the DataFlex Embedded database, use the API based ApiColumnAdd function instead.


Example


Procedure OnUpdate

    Boolean bOK

   

    Get SQLColumnAdd SysTable.File_Number "IsPrinted" SQL_Integer 2 0 True "1" to bOK   


End_Procedure