• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to convert?

 
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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";
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
: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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic