Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Split a string at the last space before 30 characters

$
0
0

I am working on a project to convert data from an old ERP system to a new ERP system.  The issue I am having is that in the old system, the product description is a varchar(255), although we don't have any descriptions that are longer than 50, and in the new system it has 2 fields that are each varchar(30).  I could easily say put the first 30 characters into description field 1 in the new system and the rest in description field 2, but then we have the issue of words being split.

I'm sure this will require a function, but is there a way to split the field at the last space before 30 characters?

So if our description is something like this "red box" and the o is at position 30, I don't want it to end up as

description 1 = ............red bo

description 2 = x

I want it to end up as 

description 1 = .............red

description 2 = box

Hopefully what I am describing here is making sense.

Thanks


Viewing all articles
Browse latest Browse all 23857

Trending Articles