Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Splitting a comma separated string issue

Author  Topic 

potn1
Starting Member

33 Posts

Posted - 2012-07-10 : 17:31:31
Hi I am using Sybase 10 and am passing a comma separated string into a stored procedure to split into multiple rows. At the moment I am only able to get this working when I pass numbers in. Anytime I pass in a word or letter I get a message saying that column doesn't exist?

ALTER PROCEDURE "DBA"."sp_split_data"(@testData varchar(500))
begin
declare @sql varchar(8000);
declare local temporary table TempTable(
testRecord varchar(500) null,
) on commit delete rows;

set @sql='insert into TempTable select '
+replace(@testData,',',' union all select ');
execute immediate @sql;

select testRecord
from TempTable
end


I call this stored procedure by: call sp_split_new_onet('1,2,3') and it will return the following:

testrecord
1
2
3

But anytime I would execute the stored procedure call sp_split_new_onet('A,B,C') it would say the columns do not exist.

So basically I am trying to find a way to split up a comma separated string where words/characters are passed in. Any help is appreciated.

Thanks!

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-07-10 : 17:55:48
I'd suggest posting your question in a Sybase forum.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2012-07-10 : 18:12:53
The following technique should work in Sybase too:

http://www.sqlteam.com/article/parsing-csv-values-into-multiple-rows
Go to Top of Page

potn1
Starting Member

33 Posts

Posted - 2012-07-10 : 19:44:29
quote:
Originally posted by tkizer

I'd suggest posting your question in a Sybase forum.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog


I tried that as well. Thanks.

quote:
Originally posted by robvolk

The following technique should work in Sybase too:

http://www.sqlteam.com/article/parsing-csv-values-into-multiple-rows


I've seen this site before but I'll give it another look.

If anyone else has any suggestions it would be much appreciated! Just annoying that it works with numbers but not letters.
Go to Top of Page
   

- Advertisement -