Database & SQL

see http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.help.ase_15.0.blocks/html/blocks/blocks125.htm

Examples

Example 1

select title, convert(char(12), total_sales) 
from titles

Example 2

select title, total_sales 
from titles
where convert(char(20), total_sales) like "1%"

Example 3

Converts the current date to style 3, dd/mm/yy:

select convert(char(12), getdate(), 3)

Example 4

If the value pubdate can be null, you must use varchar rather than char, or errors may result:

select convert(varchar(12), pubdate, 3) from titles 

Example 5

Returns the integer equivalent of the string “0x00000100”. Results can vary from one platform to another:

select convert(integer, 0x00000100)

Example 6

Returns the platform-specific bit pattern as a Sybase binary type:

select convert (binary, 10)

Example 7

Returns 1, the bit string equivalent of $1.11:

select convert(bit, $1.11)

Date Format Conversion

 

 

Convert between data types or date formats.

StyleOutput (yy)
0 mon dd yyyy hh:miAM (or PM)
1 mm/dd/yy
2 yy.mm.dd
3 dd/mm/yy
4 yy.mm.dd
5 dd-mm-yy
6 dd mon yy
7 mon dd, yy
8 hh:mm:ss
9 mon dd yyyy hh:mi:ss:mmmAM (or PM)
10 mm-dd-yy
11 yy/mm/dd
12 yymmdd

StyleOutput (yyyy)
100 mon dd yyyy hh:miAM (or PM)
101 mm/dd/yyyy
102 yyyy.mm.dd
103 dd/mm/yyyy
104 yyyy.mm.dd
105 dd-mm-yyyy
106 dd mon yyyy
107 mon dd, yyyy
108 hh:mm:ss
109 mon dd yyyy hh:mi:ss:mmmAM (or PM)
110 mm-dd-yyyy
111 yyyy/mm/dd
112 yyyymmdd

Example: select convert( char(8), getdate(), 112 )