CariDotMy

 Forgot password?
 Register

ADVERTISEMENT

View: 2892|Reply: 5

How to convert INTEGER to varchar

[Copy link]
Post time 19-12-2012 10:00 AM | Show all posts |Read mode
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




Reply

Use magic Report


ADVERTISEMENT


Post time 20-12-2012 02:44 PM | Show all posts
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)
Reply

Use magic Report

 Author| Post time 20-12-2012 03:49 PM | Show all posts
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()"
Reply

Use magic Report

 Author| Post time 20-12-2012 03:52 PM | Show all posts
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

Reply

Use magic Report

Post time 20-12-2012 04:21 PM | Show all posts
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




Reply

Use magic Report

Post time 22-12-2012 12:58 AM | Show all posts
boleh post sql code tu kat sini tak?
Reply

Use magic Report

Follow Us
You have to log in before you can reply Login | Register

Points Rules

 

ADVERTISEMENT



 

ADVERTISEMENT


 


ADVERTISEMENT
Follow Us

ADVERTISEMENT


Mobile|Archiver|Mobile*default|About Us|CariDotMy

31-12-2024 04:00 AM GMT+8 , Processed in 0.045027 second(s), 22 queries , Gzip On, Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

Quick Reply To Top Return to the list