Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data Conversion

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I would appreciate if anyone can tell me how can I convert data retrieved from a varchar database column to an integer value in sql.
I need to join two tables but the data types of the columns that I am joining are different (one is integer and the other is varchar, though the value stored is an integer value as string)

any help is appreciated
 
If this is MS SQL Server, I find that this seems to work without explicit conversion. (I guess SQL Server does the conversion automatically.)

However, perhaps this would work for you:
(I think that CAST() is ANSI92?)

Select * from LetterTable l
INNER JOIN NumberTable n
ON CAST(l.LetId as int) = n.NumId

Whatever rdms you are working in, look around for a function (like Cast) to convert from one datatype to the other.

rgrds, etc
brian perry
 
In Sybase, you would use the convert function.

Greg.
 
In Oracle, the TO_CHAR function will achieve NUMBER to VARCHAR or, if you want to go the other way, T0_NUMBER will achieve VARCHAR to NUMBER conversion.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top