I’m trying to insert trailing spaces into a VARCHAR(50) column and the SQL insert seems to be cutting them off. Here’s my code:
create table #temp (field varchar(10));
insert into #temp select ' ';
select LEN(field) from #temp;
Unfortunately, this returns a length of zero, meaning the ‘ ‘ was inserted as a ”. I need a blank space to be inserted for this column – any ideas?
Use DATALENGTH, not LEN, because LEN doesn’t process spaces.
Take this zero length string, for example:
Results: