Jaybee John Balog
Jaybee John Balog

Reputation: 27

TRIM specific column names in SELECT statement

I have a table "User" with 5 columns 'id','firstname','lastname','age','email'.

Is it possible to execute this sql command?

SELECT LTRIM(RTRIM(firstname,lastname,email)) FROM User

All i need to select is the 3 columns that are trimmed.

Upvotes: 1

Views: 3980

Answers (3)

Jesuraja
Jesuraja

Reputation: 3844

Use this:

SELECT
        LTRIM(RTRIM(FirstName)) AS FirstName,
        LTRIM(RTRIM(LastName)) AS LastName,
        LTRIM(RTRIM(Email)) AS Email
FROM    User

You need to do TRIM all the column separately.

Upvotes: 1

Fabricator
Fabricator

Reputation: 12772

You need to trim each field separately

select ltrim(rtrim(firstname)), ltrim(rtrim(lastname)), ltrim(rtrim(email))
from User

Upvotes: 3

Gordon Linoff
Gordon Linoff

Reputation: 1269483

You have to handle each column separately, as in:

SELECT LTRIM(RTRIM(firstname)) as firstname,
       LTRIM(RTRIM(lastname)) as lastname,
       LTRIM(RTRIM(email)) as email
FROM [User]

Upvotes: 2

Related Questions