Glowie
Glowie

Reputation: 2309

SQL rename column fields

I am trying to rename column output from MS SQL. I would like to remove Mac OS X 10 before outputting result, i.e.

enter image description here

When I google this, I only get how to rename column name of a table, http://www.1keydata.com/sql/alter-table-rename-column.html

Please guide

Upvotes: 2

Views: 354

Answers (1)

Tushar
Tushar

Reputation: 3623

You can use Replace function in your select or update query

The syntax is:

REPLACE( string1, string_to_replace, replacement_string )

It depends on what you need to do. You can use replace since you want to replace the value:

select replace(old_column, 'Mac OS X 10.', '')
from yourtable

Then to UPDATE your table with the new ending, you would use:

update yourtable
set column_name = replace(column_name, 'Mac OS X 10.', '')

Upvotes: 2

Related Questions