| Author |
how to convert?
|
Edward Durai
Ranch Hand
Joined: Oct 09, 2004
Posts: 223
|
|
Hi, I am using mssql. how can i convert varchar to int type. for eg. id (int) txt(varchar) 1 10 2 10a 3 10b i want to convert varchar to int. HOw? pls explain with query. Thanks edward
|
Thank You<br />Edward
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26499
|
|
Edward, So you would want to covert 10 --> 1, 10a --> 2, etc? I don't understand the relationship here. Is it just to give each varchar a unique value (you could use a sequence for this) or something else?
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
Scott Johnson
Ranch Hand
Joined: Aug 24, 2005
Posts: 518
|
|
Edward, By "convert" do you mean "get the integer associated with the string"? That would be something like: select my_integer from my_table where my_string = "10b";
|
 |
Dimit Chadha
Greenhorn
Joined: Jul 05, 2006
Posts: 2
|
|
:p Hi I think you just want to convert the varchar columns data to int data. For this first retrieve the data as varchar and then convert to int as String varchar=rs.getString("abcd"); int aa=Integer.parseInt(varchar); this will throw the parse exception if the varchar contains any characters. Otherway around , friend change the database column to int as actually you want int value . Why you r using varchar.
|
 |
 |
|
|
subject: how to convert?
|
|
|