Valid SQL LEFT() function equivalent?

Database
Fan

Valid SQL LEFT() function equivalent?

Hi all,

I am trying to select a column that has a max length of 5. If the data in the column has less than 5 characters, I pad spaces to the end of it to make it 5. In SQL, the select is written:

SELECT LEFT(Column + ' ', 5) FROM Table

What would the equivalent in Teradata be?
Tags (2)
4 REPLIES
Fan

Re: Valid SQL LEFT() function equivalent?

EDIT: Oops, I meant for the query to have 5 spaces inside the single quotes: ' '
Enthusiast

Re: Valid SQL LEFT() function equivalent?

SELECT CAST(column AS CHAR(5)) FROM table
Fan

Re: Valid SQL LEFT() function equivalent?

So that will add trailing spaces if the column has less than 5 characters?
Enthusiast

Re: Valid SQL LEFT() function equivalent?

Yes. Casting to a fixed character type returns a fixed length string. The operand value will be padded with trailing spaces or truncated to the required length.