How to PARSE a text field that is delimited by '~' character?

My data looks like this:

RecordID, NewDetailData

I need a SQL Script that will allow me to Parse out the different FIELDS that are represented by the data elements separated by the '~' character. Not the dash but the "squiggly line" character.

I need the result set like this:

RecordID,Col1, Col2, Col3, Col4 ..etc...etc..

LVL 17
MIKESoftware Solutions ConsultantAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"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.

PortletPaulEE Topic AdvisorCommented:
REPLACE ( string_expression , string_pattern , string_replacement )  

              replace([yourtable].[yourcolumn]  ,'~'  ,   ','   )

an accent (~) placed over Spanish n when pronounced ny (as in señor ) or Portuguese a or o when nasalized (as in São Paulo ), or over a vowel in phonetic transcription, indicating nasalization.
a symbol similar to a tilde used in mathematics and logic to indicate negation, inversion, etc.
Arifhusen AnsariBusiness Intelligence Developer and AnalystCommented:

I have attached the Scrip file with example.

We can do it using split function and pivot functionality. But you have to make sure that your "~" delimited data must have same number of column after parsing.

In may example i have pivoted two columns. If you want pivot more that two column you have to manually write the names of column.

Here is the snippet of the code you need to change.

SELECT * FROM #tmpData3


FOR RowNum IN ([Col1],[Col2])

) P

Open in new window

I have used only ([Col1],[Col2]). You need to modify the statement like
([Col1],[Col2],[Col3],...) and so on with the number of column you want.

Please find the attached script file. I have also attached the script file for fnSplit.

Hope it will help you.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MIKESoftware Solutions ConsultantAuthor Commented:
GREAT WORK,...PERFECT! This is exactly what I was looking for.

Many thanks!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.