CFLib.org – Common Function Library Project

MSSQL2CFSQLDT(dataType)

Last updated May 9, 2009

author

C. Jason Wilson

Version: 0 | Requires: CF6 | Library: DatabaseLib

Description:
Convert Microsoft SQL Server Data Type to equivilent CFSQLType. Most usefull when querying MS SQL Server sys tables to return data type from the table structure and converting to a CF data type for use within the <cfqueryparam> tag.

Return Values:
returns a string

Example:

#MSSQL2CFSQLDT('nvarchar')#  returns  CF_SQL_VARCHAR

Parameters:

Name Description Required
dataType String of datatype to use Yes

Full UDF Source:

/**
 * Convert Microsoft SQL Server Data Type to equivilent CFSQLType
 * Most useful when querying MS SQL Server sys tables to return data type from the table structure and converting to a CF data type for use within the <cfqueryparam> tag.
 * 
 * Example Usage
 * #MSSQL2CFSQLDT('nvarchar')#  returns  CF_SQL_VARCHAR
 * 
 * Author C. Jason Wilson (cjwilson@cf-developer.net) 
 * version 1, January 13, 2009
 * 
 * @param dataType 	 String of datatype to use (Required)
 * @return returns a string 
 * @author C. Jason Wilson (cjwilson@cf-developer.net) 
 * @version 0, May 9, 2009 
 */
function MSSQL2CFSQLDT (DataType) {
	var MSSQLType = 'int,bigint,smallint,tinyint,numeric,money,smallmoney,bit,decimal,float,real,datetime,smalldatetime,char,nchar,varchar,nvarchar,text,ntext';
	var CFSQLType = 'CF_SQL_INTEGER,CF_SQL_BIGINT,CF_SQL_SMALLINT,CF_SQL_TINYINT,CF_SQL_NUMERIC,CF_SQL_MONEY4,CF_SQL_MONEY,CF_SQL_BIT,CF_SQL_DECIMAL,CF_SQL_FLOAT,CF_SQL_REAL,CF_SQL_TIMESTAMP,CF_SQL_DATE,CF_SQL_CHAR,CF_SQL_CHAR,CF_SQL_VARCHAR,CF_SQL_VARCHAR,CF_SQL_LONGVARCHAR,CF_SQL_LONGVARCHAR';
	
	if(ListFind(MSSQLType,DataType)) {
		return ListGetAt(CFSQLType,ListFind(MSSQLType,DataType));
	} else { return 'NULL'; }
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson