I'm looking for a little help in splitting apart a field that uses multiple delimiters in a sql function/ statement. I've followed a few examples already listed HERE
here that work very well with a single delimiter. However I need to split apart a field that is based on the following. its format would be qty x itemno description, qty x itemno description, etc. I therefore need to break apart the statement on the first ' x' the second space ' ' and the final comma.. I figure I can split this based on a regular expression statement but unsure about how to go about it..
could anyone help?
OnSameLine = substring( ( SELECT ', ' +
coalesce (CAST(CNT.qty AS varchar(1000)), '') +
' x ' + '['+ coalesce (CNT.Itemno,'') + ']' +
' ' + coalesce (STK.Desc#1,'')
format I need..
PK qty itemno description
PK qty itemno description
etc..
If you just want to split by , and exchange Qty and PK, try this;
SQL Fiddle here
If you want to split them into columns then try this;
SQL Fiddle here
Try this:
Based on article from here