Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
angelntn
Starting Member
2 Posts |
Posted - 2012-01-31 : 19:56:15
|
| hi. i'm a noob of sql.i wanna know if is possible to create a query in sql that can replace the name of columns in a table where there are spaces with the same name with underscore.ex. i have this table: teachersand this columns: id teacher name surname monthly salaryi wanna this:column: id_teacher name surname monthly_salaryi know that there's a function call replace().someone could help me? |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-01-31 : 19:58:17
|
use belowEXEC sp_rename 'teachers.[monthly salary]', 'monthly_salary', 'COLUMN'; ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
angelntn
Starting Member
2 Posts |
Posted - 2012-01-31 : 20:52:55
|
| ok. perfect.but i need something like a procedure.this is my problem.i wanna migrate my db from access to sql server.i use ssma for this but a lot of columns in my db have a space in the name. (ex. [monthly salary])ssma reports to me a lot of warnings for this identifiers.could i make a procedure for replace the name of all this columns???? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-02-01 : 09:29:49
|
| why not write a logic to serach within INFORMATION_SCHEMA.COLUMNS view for columns with space in between and then call sp_rename to make them _ instead?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|