Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

Splitting a multi-delimiter string and update

$
0
0
So I am trying to fix something a developer did in our database and I'm having trouble figuring this out. First about the string itself. It is a double delimited string, the first value is a text description and the second is a unit price as shown below. The two delimiters are the tilde and carrot characters. Sharpening~11.44^Face Shear~17.16^(1) STD Tip(s) replaced (0.250 kerf)~52.64^Here is the messed up part. This value is stored on a parent record. Not parent in that the child is in another table, but the child is in the same table, different line number. Here is the condensed table and some sample data. The Service_Op Column is empty for now. Company | OrderNum | OrderLine | Part | LineDesc | Pricing | Service_Op100 | 109187 | 1 | SKP | Sales Kit Part | Sharpening~11.44^Face Shear~17.16^(1) STD Tip(s) replaced (0.250 kerf)~52.64^ | 100 | 109187 | 2 | CS1 | Component1 | |100 | 109187 | 3 | CS2 | Component2 | | 100 | 109187 | 4 | CS3 | Component3 | |Here is what I need the data to look like. I need the Service_Op column updated for the child parts as show below. The string length is variable, so the solution would need to be dynamic and the parent isn't always on line 1, but all childs of that parent are in sequential order after the parent. 100 | 109187 | 1 | SKP | Sales Kit Part | Sharpening~11.44^Face Shear~17.16^(1) STD Tip(s) replaced (0.250 kerf)~52.64^ | 100 | 109187 | 2 | CS1 | Component1 | | Sharpening100 | 109187 | 3 | CS2 | Component2 | | Face Shear100 | 109187 | 4 | CS3 | Component3 | | (1) STD Tip(s) replaced (0.250 kerf)Basically I need to split the string by the delimiters, ignore the unit price and if need be create a separate array of just the strings w/o unit prices, then loop the array and join on ordernum and current orderline + the current array position + 1 and update the service_op column with the current array value. I'm doing this because reporting has become a nightmare. Is that possible?

Viewing all articles
Browse latest Browse all 3145

Trending Articles