How can i cast integer to varchar

Posted on 2010-11-08
Last Modified: 2012-05-10
SELECT cast(cont as varchar(255)) FROM aa;  is giving error.

Question by:sam2929

Accepted Solution

db2inst1 earned 500 total points
ID: 34086238
You could do the following

select char(cont) from aa;

If you really want varchar

select varchar(char(cont)) from aa;
LVL 18

Expert Comment

ID: 34086346

Both of these work beautifully for me on DB2 for i (version 6.1)  -- DaveSlash

select varchar(anInteger)

from   MyTable

select cast(anInteger as varchar(255))

from   MyTable

Open in new window

LVL 37

Expert Comment

ID: 34086351
Which error do u get?

Author Comment

ID: 34086442
EE mobile sounds good
LVL 45

Expert Comment

ID: 34086524

Dave's solutions work on LUW, too.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Last 4 fiscal years for a given date 8 212
RPG Free Prototypes using  *LDA data 5 164
Data transfer to iSeries failing with message ID SQL0462 6 122
find age for two dates 5 32
November 2009 Recently, a question came up in the DB2 forum regarding the date format in DB2 UDB for AS/400.  Apparently in UDB LUW (Linux/Unix/Windows), the date format is a system-wide setting, and is not controlled at the session level.  I'm n…
Recursive SQL in UDB/LUW (it really isn't that hard to do) Recursive SQL is most often used to convert columns to rows or rows to columns.  A previous article described the process of converting rows to columns.  This article will build off of th…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now