473,407 Members | 2,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Varchar to Integer Typecast

I need to convert a varchar to Integer to compare if it is in the range. The problem is there might be few rows which have characters in them instead of numbers. This column either contains a number like '01','04', '15' etc or say a name. How can i achieve this? Is it possible.
Jan 30 '07 #1
2 34092
iburyak
1,017 Expert 512MB
Something like this:
[PHP]

select cast(column_name as int) from table_name
where column_name not like '%[a-z,A-Z]%'[/PHP]
Jan 30 '07 #2
almaz
168 Expert 100+
I guess better approach would be to use built-in functions ;)
Expand|Select|Wrap|Line Numbers
  1. select convert(int, convert(decimal, column_name)) from table_name
  2. where isnumeric(column_name) = 1
Nested convert statements are required to handle fractional numbers
Jan 31 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Bill | last post by:
In an effort to improve the speed of queries against my main table, I'll be indexing a column whose data type is varchar(50). Would I be better off (better performance) if I changed the column's...
3
by: pw | last post by:
Hello, How can I typecast a date generated from VARCHAR fields into a date field ie: UPDATE inventory SET date_field = vc_year||'-'||vc_month||'-'||vc_day;
10
by: Techie | last post by:
what's the difference of the two data types?
7
by: James o'konnor | last post by:
hello. i have the next for create one table into db2 CREATE TABLE "MYSQUEMA"."TABLADEMO" ( "ID" INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY ( START WITH +0 INCREMENT BY +1 MINVALUE +0...
6
by: Ying Lu | last post by:
Hi, I have a question about alter a column's type in a postgreSQL table. For example, I have 10, 000 records in a table name "test", I'd like to change column "machineID" type from integer to...
2
by: rootman | last post by:
Hi @all i try to create a ssh public key database on a mysql-5.0.16 DB the problem is the size of the varchar, i want a size 1024... mysql> create table sshkeys ( absid integer unsigned...
3
by: ryan.gilfether | last post by:
I have a problem that I have been fighting for a while and haven't found a good solution for. Forgive me, but my C++ is really rusty. I have a custom config file class: class ConfigFileValue...
3
by: Okonita | last post by:
Hi everyone, I have been building a set of tables for a new database and having problem with tables having columns defined as Long Varchar. Can someone look this over and tell me what I am doing...
3
by: gertie2008 | last post by:
I'm trying to get the 3rd query to return a varchar, but it returns an integer. Query one to prove that a varchar can be returned: SELECT IF(1=1,0,'one'), IF(1=0,0,'one'); ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.