Reputation: 1455
I have a table which has a field that allows up to 120 chars. I want to split the field into three fields. If the field contains more than 40 chars and less than 80 then split the field into two. The split point should be the first space char, before the 40th character and add the two new fields to another table. and if the field is 120 char then split them in three.
Will appreciate the help!
Upvotes: 1
Views: 56
Reputation: 19544
I guess you could do something along the lines of:
SELECT
SUBSTRING(MyCol,1,40),
NULLIF(SUBSTRING(MyCol,41,40), ''),
NULLIF(SUBSTRING(MyCol,81,40), ''),
To have your 1 column broken down correctly for your INSERT
statement.
The NullIf
function will set whatever column needs to be NULL
correctly if the SubString()
function returns an empty string for that value.
Upvotes: 1