Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL Server 2005 parse string into two column table

Posted on 2013-01-30
6
Medium Priority
?
379 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
  • 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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

876 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