Question

If the word

(xxxx) British White

has had the (xxxx) copied to a new field, how do i write an expression to remove (xxxx) to leave British White?

British White

I have experimented with trim both left and right but it only seams to remove spaces.

Was it helpful?

Solution

Option 1: Fix it in post

Assuming you're going to SQL from a file, just stage the data in a table as-is and then fix it in your final table.

UPDATE 
FinalTable
SET
Column = SUBSTRING(Column, CHARINDEX( ' ' , Column) + 1 , LEN( Column ) ) 

Pros

  • Preserve the source in case you want to do something different to it later. (This is a huge pro most people seem to gloss over.)
  • SQL is generally speaking easier for others to maintain (more people grok it) and can be encapsulated in more places (stored procedure, managed code, etc.)

Cons

  • Probably just going to stick the UPDATE statement in the SSIS package anyway.
  • IO driven, if performance is an issue.

Option 2: Derived Column

Derived Column syntax:

RIGHT(Column,LEN(Column) - FINDSTRING(Column," ",1))

The 1 in the FINDSTRING function means use the first occurrence. If there is no space, it returns 0 and thus the expression just returns the original column.

Pros

  • Memory-driven.
  • All business logic encapsulated in package.

Cons

  • Not preserving source.
  • Have to document this somewhere outside the package so the next guy knows what's going on.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top