Experts Exchange Solution brought to you by
"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.
--create a table to host imported data
CREATE TABLE #SampleOutput
[CreatedDate] varchar(50) null,
[FailureReason] varchar(255) null,
[FromUser] varchar(50) null,
[QSource] varchar(255) null
--Now run following script to load all the data from CSV to database table. If there is any error in any row it will be not inserted but other rows will be inserted.
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
--Check the content of the table.
SELECT * FROM #SampleOutput;
DROP TABLE #SampleOutput;
Open in new window
DECLARE @myList nvarchar(max) = '1,2,3~4,5,6~7,8,9~10,11,12';
declare @xml xml = cast(concat('<root><row>', replace(@myList,'~','</row><row>'), '</row></root>') as xml)
;with cte as
Select f.value('text()','NVARCHAR(MAX)') v from @xml.nodes('//row') t(f)
Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.
From novice to tech pro — start learning today.
Members can enroll in this course at no extra cost.