I have a table called PurchaseOrderDetail.
TABLE PurchaseOrderDetail
PurchaseOrderDetail int,
Comments nvarchar(500)
In the Comments field of each item I have a ‘;’ separated list that stores A Contract Name, Contract No, License Name, License Version.
i.e.
PurchaseOrderDetail Comments
1 'Microsoft Office Standard 2007;12%;;'
2 'Microsoft Visio 2007;9%;;'
I also have a function called Split that takes a delimiter and a string and returns a table,
So calling this select * from Split(';', 'Microsoft Office Standard 2007;12%;;')
returns this
pn s [ column names]
1 Microsoft Office Standard 2007
2 12%
I need to break this information out for each PurchaseOrderDetail and show them in a report
So something like this
select PurchaseOrderDetailID, cn.s as ContractName, cno.s as ContractNo
from dbo.PurchaseOrderDetail as pod
join dbo.Split(';', pod.Comments) as cn on cn.pn = 1
join dbo.Split(';', pod.Comments) as cno on cno.pn = 2
although that doesn’t run, but I hope it suggests intent.
I’d like my results to be:
PurchaseOrderDetailID ContractName ContractNo
1 Microsoft Office Standard 2007 12%
Is it possible, or am I tackling this the wrong way