SQLTeam.com | Weblogs | Forums

Convert INT will not work


#1

i have a field called measurement filed that has numeric data in it. I am trying to convert measurement from varchar to int but i want a sum of measurement from my table called WOTask.


#2

you can use CONVERT() or CAST() to convert from varchar to int.

Are you facing any issue doing that ? Any error message and sample data for us to better understand your problem
?


#3

Measurement is a column in my WOTASK table with numeric values in it.

I keep getting an error message
Conversion failed when converting the varchar value to data type int.


#4

CONVERT (int, fieldname)

please send me the table with table structure.


#5

or use another approach, suppose if you have number and character field in one column then use below code.

CASE WHEN ColumnField LIKE '%[^0-9]%' THEN NULL ELSE CONVERT (int , ColumnField) END


#6


#7

Is above my query not work with you?


#8

no that query did not work receiving error message


#9

Your image is cutting off part of the data. Post DDL for the table and inserts for sample rows.
Thanks


#10

what was the error.

You can please send me the script and data through insert query.


#11

Hello I am trying to do the following:

select sum(measurement) from wotask when doing this i receive the following error message "Operand data type varchar is invalid for sum operator" I have tried the convert, case, ect and receive the same error message. Measurement is (varchar(50),null) and has numeric data


#12

dear send me proper query and table structure


#13

To use SUM you will need to convert (or cast) the VARCHAR to a numeric before the SUM.


#14

Yes your right, but i'm asking you is send me the table structure like create table and columns

and your insert query so i will test and send you with result.

thanks
basit.