Previous Topic

Next Topic

Inhoudsopgave

Book Index

Convert And Cast

Convert( datatype [(length) | (precision [, scale])] [null | not null], expression [, style])

Cast( expression as datatype [(length) | (precision [, scale])] )

Converts expressions to the specified data type. In ASE you can specify the nullability of the resulting datatype.

Example

create table t1 (c varchar(10) null)

insert into t1 values ('1.5')

insert into t1 values (NULL)

select i = convert(numeric(5,2) null, c) into t2 from t1

select * from t2

drop table t1

drop table t2

Difference

In ASE the datatype can be passed as a quoted string. This is not possible in MS SQL Server.

select Convert( 'int', '123' )

select Cast( '123' as 'int' )

MS SQL Server does not have the nullability specification. The converted datatype in MS SQL Server is always nullable. As a result, the code fragment below works in MS SQL Server, but gives an error in ASE.

create table t1 (c varchar(10) not null)

insert into t1 values ('1.5')

select i = convert(numeric(5,2), c) into t2 from t1

insert into t2 values (null)

select * from t2

drop table t1

drop table t2

Note: For the examples above to work, in the ASE database you have to set the option ‘select into/bulkcopy/pllsort’.