Powered by Blogger.

Saturday, February 15, 2014

How to trim spaces in column values in sql server 2008?



In this post we will discuss how we can get trims values of a column in sql server 2008.

Also you can check out my previous posts on:

- Logging In Users Programmatically in Asp.Net

- How to get distinct data from tables in sql server 2008?

- Tutorial on Tuple in C#.Net 4.0

Suppose you have a column name as firstname of varchar type and if it contains any white spaces then when you run the select sql statement like below,

Select firstname from employees

Then it will return all the firstname of all the employees but also the whitespaces will come if any with the names.

so to trim the spaces you can write the select sql statement like below:

SELECT LTRIM(RTRIM(firstname)) AS FirstName from employees

This will trim the whitespaces from the column values.



0 comments

Post a Comment