Hi All,
Im experimenting with the in database tools as a way to improve my processing speeds and its very effective, however in previous tools I have used I would have used a simple split expression to extract information from fields to new columns eg split([field], ' ' , 2]) , and I know there's a good split columns fucntion in the in memeory toolset, but the in database formula tools require a SQL statement.
I've gone through countless examples of varying and mind dboggling complexity (one guys written an impressive thesis on the topic) but can't make anything work.
Anyone have any solutions to writing a SQL statement to split the below string on the 3rd under score
So that my current column value of 'product code': 123_3456_78910_45_45_bvAGSBD6252-BT56383
can generate the new columns of short code: 123_3456_78910
Many thanks in advance
Solved! Go to Solution.
This SQL statement is somewhat awkward and probably not the most efficient way to accomplish what you want, but it is functional in cases where you have 3 underscores.
You can create your first column using the following Formula In-DB:
LEFT("product code",CHARINDEX('_',"product code",CHARINDEX('_',"product code",CHARINDEX('_',"product code")+1)+1)-1)
CHARINDEX() lets you find the first instance of a certain character in a field, and returns its position. So if you nest CHARINDEX() formulas, using a +1 to increment PAST the last underscore we found, you can find the next one. Then in the LEFT() statement to pull only the left side, you can subtract one character to remove the final underscore.
Assuming you name this column "short code", you can create the second column using the following formula. You will need a second Formula In-DB tool to do this.
RIGHT("product code",LEN("product code")-LEN("short code"))
Boom. it works.
Thnx for that, and the explanation. The + - bit was really throwing me.