I have a table (book) where there is a column that contains number in some rows and numbers with an addition *infront. I want to be able to perform some calculation with the table but the '*' is preventing me from doing this. So how do I update or alter the table so that I can remove the * and keep the numbers?
*99
*12
23
*68
*48
89
13
Thanks works great!
On another note, is there a way to split the column into 2 so that 1 column shows whether that number has a * prefix or not?
eg
* |99
* |12
null |23
* | 68
* | 48
null | 89
null | 13
Assuming that you are using SQL Server, you could use the SUBSTRING and CHARINDEX functions.
Something like this:
SELECT SUBSTRING(your_column,CHARINDEX('*',your_column),1) has_asterisk,
SUBSTRING(your_column,CHARINDEX('*',your_column)+1,LEN(your_column)) number FROM book;
If you are using Oracle, you should use SUBSTR and INSTR instead.
Free Guide: Managing storage for virtual environments
Complete a brief survey to get a complimentary 70-page whitepaper featuring the best methods and solutions for your virtual environment, as well as hypervisor-specific management advice from TechTarget experts. Don’t miss out on this exclusive content!
Discuss This Question: 4  Replies
* |99 * |12 null |23 * | 68 * | 48 null | 89 null | 13
SELECT SUBSTRING(your_column,CHARINDEX('*',your_column),1) has_asterisk, SUBSTRING(your_column,CHARINDEX('*',your_column)+1,LEN(your_column)) number FROM book;
If you are using Oracle, you should use SUBSTR and INSTR instead.UPDATE book SET your_column = REPLACE(your_column,'EMP','')