If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Data Type Conversion

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-19-09, 04:35
girishkardam girishkardam is offline
Registered User
 
Join Date: Mar 2009
Posts: 5
Data Type Conversion

Hi All,

I want to know how I can convert int datatype to varchar how I do the same.

query is : select convert(DesignationCode,varchar(200) from employee;

above query is showing error

But when i used char(200) instead of varchar it is working fine.


Kindly guide me how to use varchar in datatype conversion.

with regards
Girish Kardam
Reply With Quote
  #2 (permalink)  
Old 03-19-09, 04:46
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
try CAST(DesignationCode AS CHAR)
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 03-19-09, 04:49
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
Has the missing paren got anything to do with the error?
Code:
SELECT Convert(DesignationCode, varchar(200)
FROM   employee;
__________________
George
Twitter | Blog
Reply With Quote
  #4 (permalink)  
Old 03-19-09, 04:54
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
check da manual, george

correct syntax, let me show u it
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 03-19-09, 05:23
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
Oops
Code:
Convert(varchar(200), some_field)
__________________
George
Twitter | Blog
Reply With Quote
  #6 (permalink)  
Old 03-19-09, 05:49
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
oops is right

what forum are you in? did you check da mysql manual???
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #7 (permalink)  
Old 03-19-09, 06:24
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
dev.mysql will never load from this location, so no, I did not.
__________________
George
Twitter | Blog
Reply With Quote
  #8 (permalink)  
Old 03-19-09, 06:27
girishkardam girishkardam is offline
Registered User
 
Join Date: Mar 2009
Posts: 5
Hi r394,


I had gone through the mysql manual after that only i posted my query in the forum. As i didn't find any solution for converting int datatype to varchar.


with regards
Girish Kardam
Reply With Quote
  #9 (permalink)  
Old 03-19-09, 07:20
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
Originally Posted by gvee
dev.mysql will never load from this location, so no, I did not.
oh, i see

well, that's okay then

just keep posting stuff from the sql server manual, then

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #10 (permalink)  
Old 03-19-09, 07:37
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
okay, to be somewhat more helpful...

next time you're on a computer that can access dev.mysql.com, george, download one of the CHM files, and copy it to a floppy (or a usb memory stick or whatever) and take that with you

the CHM is a ~lot~ easier to search and browse than going to dev.mysql.com anyway

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #11 (permalink)  
Old 03-19-09, 11:06
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
I should also point out that MySQL will automatically convert numbers to characters when required ie select concat( 1234,"a") will produce "1234a".
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On