user3279082
user3279082

Reputation:

Trim space for a column In sql server 2008

How can I possible trim a white space before my column. I have a column called Cost and I have given a white space before.

[ Cost] [int] NULL,

I am using these queries and doesn't work. Can anyone correct me.

SELECT REPLACE(Cost, ' ', '')

select REPLACE (' Cost', ' ', '' )

Upvotes: 0

Views: 316

Answers (1)

Kaspars Ozols
Kaspars Ozols

Reputation: 7017

I guess you should change table definition so that column name does not have white space in it. You can do that with sp_RENAME procedure.

EXEC sp_RENAME 'TableName.[ Cost]' , 'Cost', 'COLUMN'

If you can't do that, you can refer column using square braces:

SELECT [ Cost]
FROM TableName

Upvotes: 4

Related Questions