Click here to Skip to main content
15,949,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi

suppose i have a table with name "Transport"

in this table i have 3 fields : a,b,c

how i can subtract a-b and put in c field

Note :
1- unfortunately , all fields have text type .
2- now , this table have about 5000 record and i cant change field type or anything else , and i want only update field c with subtract of a-b

thanks guys
Posted
Comments
[no name] 7-Oct-14 15:10pm    
String - string = ? What is it that you think you are subtracting?

1 solution

It's bad idea to store numbers as a text.

You have to use query similar to:
SQL
UPDATE Transport SET c = CLng(a)-CLng(b)


As you can see, i use CLng function to convert text to long integer.
Note: Conversion may failed when text stored in that field cannot be explicitly converted.

For further information, please see:
CLng function[^]
UPDATE statement[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900