JJ.
JJ.

Reputation: 9960

how to pad "x" to the end of a string of fixed length

This code:

select right('XXXXXXXXXXX' + 'BARCGB22', 11)

Results in: "XXXBARCGB22"

But I need the reversed and I'm having a hard time doing it. It needs to be:

"BARCGB22XXX"

Can anyone give me a quick hand?

Thanks

Upvotes: 0

Views: 67

Answers (1)

Shawn
Shawn

Reputation: 4786

I'm assuming BARCGB22 will be coming from a variable. I'd use SELECT left(coalesce(myvar,'')+'XXXXXXXXXXX', 11). `NULL' kinda has a special meaning and it behaves a bit different from a normal variable.

EDIT:

Or '...isNull(myvar,'')....isNull()andcoalesce()do just about the same thing, butisNullis T-SQL whilecoalesce` is more generic.

Upvotes: 4

Related Questions