Google Answers Logo
View Question
 
Q: MS SQL Server: Comma-delimited list converted into a table. ( No Answer,   0 Comments )
Question  
Subject: MS SQL Server: Comma-delimited list converted into a table.
Category: Computers
Asked by: infiniteblue-ga
List Price: $20.00
Posted: 12 Dec 2002 22:32 PST
Expires: 12 Dec 2002 23:50 PST
Question ID: 124024
/*
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.

*/
Answer  
There is no answer at this time.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy