October 17, 2008 at 8:43 am
Hi
I have a column with datatype char(2). I want to add a fixed number say 7 to each of its record and store it as new column. Something like this:
Col_original Col_new
007
018
029
0310
etc
something like.. i want to perform arithmetic operation on char column which in this case is addition.
I think i should be able to convert 'Col_original' to int type AS
Col_original
0
1
2
3
Then , addition should be easy.
Please suggest,
Thanks
October 17, 2008 at 8:50 am
Yes you can do what you are planning and pretty simply as long as all the character values CAN be converted to integer. I'd do it something like this:
Update table
Set int_column = Convert(int, char_column) + 7
Where
-- only do it to covertable columns
IsNumeric(char_column) = 1
Then I can look for Nulls in the int_column which will help me find and fix inaccurate data in the char_column. The only issue with IsNumeric is that is considers '.', '+', '-', and currency symbols to be numeric so you could still get some errors.
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply