Useful link for type Casting in MySql with good Example
CAST(expression as type)
The type can be one of the following values:
BINARY[(N)]
CHAR[(N)]
DATE
DATETIME
DECIMAL[(M[,D])]
SIGNED [INTEGER]
TIME
UNSIGNED [INTEGER]
More Example :
If a field with datatype VARCHAR(100) and also have a value “0420″
For normal selection of data you got a value 0420 which is a string. But you want a integer value that is 420.
You can write a sql like
SQL query: SELECT CAST(fld_name AS UNSIGNED INTEGER) as
fld_name FROM tbl_name LIMIT 0,1;
The type can be one of the following values:
BINARY[(N)]
CHAR[(N)]
DATE
DATETIME
DECIMAL[(M[,D])]
SIGNED [INTEGER]
TIME
UNSIGNED [INTEGER]
More Example :
If a field with datatype VARCHAR(100) and also have a value “0420″
For normal selection of data you got a value 0420 which is a string. But you want a integer value that is 420.
You can write a sql like
SQL query: SELECT CAST(fld_name AS UNSIGNED INTEGER) as
fld_name FROM tbl_name LIMIT 0,1;
No comments:
Post a Comment