Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL Server 2005 parse string into two column table

Posted on 2013-01-30
6
Medium Priority
?
378 Views
Last Modified: 2013-01-30
In VB I am building a string which I am passing into my stored procedure as a varchar(MAX) variable

The string looks like this

Larry,100|jane,125|Bill,75

I want to parse this into
col1      col2
Larry     100
Jane       125
Bil           75
0
Comment
Question by:lrbrister
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 23

Accepted Solution

by:
Ioannis Paraskevopoulos earned 1500 total points
ID: 38835848
Hi,

You would have to use an sql cursor. Are you inserting the results in a table?

Giannis
0
 

Author Closing Comment

by:lrbrister
ID: 38835871
You joggled my memory with the "Table" comment

I remember getting some code from angelll years ago.

SELECT      MAX(CASE WHEN row_num % 2 = 1 THEN Value END) hsid,
        MAX(CASE WHEN row_num % 2 = 0 THEN Value END) hours
FROM      dbo.ParmsToList(@list, ',') d
GROUP BY(row_num - 1)/ 2
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 38835872
using the function dbo.ParmsToList, code being here:
http://www.experts-exchange.com/Database/Miscellaneous/A_1536-delimited-list-as-parameter-what-are-the-options.html

you can do it without a "cursor":
select left( f.value, charindex(',', f.value) - 1) col1
, substring( f.value, charindex(',', f.value) + 1, len(f.value))  col2 
  from dbo.ParmsTolist('Larry,100|jane,125|Bill,75', '|') f 

Open in new window

0
Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 38835881
too slow :)
0
 

Author Comment

by:lrbrister
ID: 38835891
angelll,
I have received some great help from you for the past 10 years or so.

Usually, I just need to take a moment and look through what you gave me in the past already
0
 
LVL 23

Expert Comment

by:Ioannis Paraskevopoulos
ID: 38835929
Hi,

If you want (i don't know if you can) to reallocate the points, it is fine by me. After all i really didn't think that was of much help. I really expected to just start a conversation and then give you an answer.

:)

Thanks anyways,
Giannis
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question