All Forums Database
dgreen 3 posts Joined 04/11
18 Apr 2011
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:
dgreen 3 posts Joined 04/11
18 Apr 2011

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

Jim Chapman 449 posts Joined 09/04
18 Apr 2011

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

dgreen 3 posts Joined 04/11
18 Apr 2011

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

Jim Chapman 449 posts Joined 09/04
18 Apr 2011

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.

You must sign in to leave a comment.