I know that this question has been asked many times but could not find what I needed.
I have this column "Order" which contains data in the following format. 'xxx,yyy,zzzz'
Now when I do my select
statement I need to populate 3 columns by splitting this one
E.G.
Select Name,
Surname,
FirstCommaColumn=xx.UpToFirstColumn
SecondCommaColumn=xx.FromFirstCommaToLastComma,
ThirdColumnFromSecondCommaOnwards=FromSecondCommaToEnd
from myTable
--thought of doing something like
CROSS APPLY (SELECT TOP 1 * FROM dbo.SplitFunctionIDontHave(order,',')) AS xx
There are some rows which have no commas so I must return blank. I don't mind if I do in a function or within the query itself just not sure how to do this.
How can I do this using SQL Server 2008? This select is part of a view if makes a difference