/*
I need to be able to convert an inputed list of delimited values into
a table. Seems simple enough, however I've been scratching my head for
hours on this. I'd greatly appreciate any help from SQL gurus.
Platform: SQL Server 2000
*/
DECLARE
@vcPartNum varchar(8000)
,@vcVendorPart varchar(8000)
,@vcLineItem varchar(8000)
,@vcUnitCost varchar(8000)
,@vcUnitPrice varchar(8000)
,@vcQty varchar(8000)
-- These variables are just comma delimited lists of the needed fields
SET @vcPartNum = 'A1123,A1456,A1789'
SET @vcVendorPart = 'D123,D456,D789'
SET @vcLineItem = 'Item1,Item2,Item3'
SET @vcUnitCost = '13.23,12.34,56.56'
SET @vcUnitPrice = '12.32,45.46,78.09'
SET @vcQty = '2,4,8'
/*
These comma-delimited lists need to be split into this table:
Any item, in any field may be empty (e.g: '123,,456,789' or
'D123,D456,')
In that case, a NULL value should be inserted in the missing value's
place.
*/
DECLARE @Order table (
PartNum varchar(25)
,VendorID smallint
,VendorPart varchar(30)
,LineItem varchar(200)
,UnitCost money
,UnitPrice money
,Qty int )
/*
Misc points:
* The query cost is important; solutions involving cursors are not
workable.
* I am using a comma as a delmiter here for simplicity. In practice, I
am using a high-ascii character.
*/ |