Unanswered: How to verify & Convert char value to int?
I have varchar(10) column in a table which holds most of the time numeric data or 'A' value. Now I want to select that data as int. If the value is 'A', I should get 0 (Zero) value. If I use convert(int,column), it will work most of the time except when the value is 'A'. How can I write this query?
Originally posted by nmr
Thanks for the idea.
Addition to that, if I have more than one char like 'AA','ZB'.. how can I verify that.
The ascii function returns the ascii value for the first character in a varchar field. So, you can use this for longer strings, so long as the first character is always a letter. Where you will run into problems is if it is possible for your fields to be populated with '1AQ'... and at that point I'm stumped - unless you cycle through every character in the varchar field and test each individually (*shudder*)
If anyone knows of a better way to do this, I'm interested too!