Which is faster to remove leading spaces and zeros: Cast or Trim?

Database
Enthusiast

Which is faster to remove leading spaces and zeros: Cast or Trim?

Hello, i have a column (STORE_ID) that contains only numeric characters and in some cases leading spaces.  I want to trim leading zeros and spaces.  Which is faster? 

 

cast(cast(STORE_ID as integer) as Varchar(75))

 

trim (leading '0' from trim(leading from STORE_ID))

 

3 REPLIES
Junior Contributor

Re: Which is faster to remove leading spaces and zeros: Cast or Trim?

None of them :-)

You can use

LTRIM(STORE_ID, '0 ')

to trim multiple characters.

Enthusiast

Re: Which is faster to remove leading spaces and zeros: Cast or Trim?

Great!  Thanks!  and that will left trim them in any order they appear, for any number of occurences?  In other words it will remove '   0', '0   ', ' 0000', '      00000', etc?

Junior Contributor

Re: Which is faster to remove leading spaces and zeros: Cast or Trim?

Yep, any leading ' ' and '0' in any order will be removed, simply try it.