View: 2893|Reply: 5
|
How to convert INTEGER to varchar
[Copy link]
|
|
salam,
sapa2 ada formula tok convert INT to varchar, boleh share tak. cth :
saya ada field kod_pejabat=101010 (int (4)) n sy nak convet ke data type varchar(4)
DB : SQL
Language : PHP
|
|
|
|
|
|
|
|
convert(varchar(4),kod_pejabat)...
--> select convert(varchar(4),kod_pejabat) FROM TableName
tp kenapa nk convert ke length(4)... sbb tgk sample data kod_pejabat tuh mcm 101010 = length(6)
adakh sebab nk amik 4 terawal?.. kalo nk amik 4 terawal just
--> select left(kodpejabat,4) |
|
|
|
|
|
|
|
alam. posted on 20-12-2012 02:44 PM
convert(varchar(4),kod_pejabat)...
--> select convert(varchar(4),kod_pejabat) FROM TableName
tq bro.
tp bila sy buat coding tuh kuar error gni "Fatal error: Call to undefined function convert()"
|
|
|
|
|
|
|
|
alam. posted on 20-12-2012 02:44 PM
convert(varchar(4),kod_pejabat)...
--> select convert(varchar(4),kod_pejabat) FROM TableName
bab data tuh plak, sy pun x leh nak jawab, sbb sy tgk format db lama int(4), tp db baru lak varchar(4)
tp kalau tgk data yg nak transfer tuh samapai 8 digit pun ada
|
|
|
|
|
|
|
|
isms posted on 20-12-2012 03:52 PM
bab data tuh plak, sy pun x leh nak jawab, sbb sy tgk format db lama int(4), tp db baru lak varcha ...
ummmmmmmmmm mcm mana datatype int(4) tp data length sampai 8.. xpa lh forget it...
hah guna MS SQL or mySQL..
kalo mySQL
--> select cast(tableNAme.Kod_Pejabat as char(4)) from TableName
|
|
|
|
|
|
|
|
boleh post sql code tu kat sini tak? |
|
|
|
|
|
|
| |
|