一、convert

CONVERT: CONVERT(data_type[(length)], expression [, style])

 注:参数data_type为想要转换的数据类型,expression 为SQL Server表达式

示例:

select convert(float,'123456') as UserCode
--结果:123456

select convert(float,'') as UserCode
--结果:0

select convert(float,NULL) as UserCode
--结果:NULL

二、cast

CAST ( expression AS data_type )

注:参数data_type为想要转换的数据类型,expression 为SQL Server表达式

示例:

select CAST( '123456' AS float) as UserCode
--结果:123456