question

John Smith avatar image
John Smith asked

sql query to strip out text from an entry

Hi,

I want to write an sql that strips out the text from an entry and just retain the numbers and relational operators.

For example, my student table is

                    
StudentID  Marks                    
1          scored >80 marks                    
2          scored =80 marks                    
                    
I want to update my student table to be                    
                    
StudentID  Marks                    
1          >80                    
2          =80                    

Can someone please help me with this sql.

Thanks

sql-server-2005queryupdate
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

· Write an Answer
Piotr Rodak avatar image
Piotr Rodak answered

Have a look at the REPLACE function:

update student set marks = replace(replace(marks, 'scored ', ''), ' marks', '')            
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.