SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Using DelimitedSplit8k against a Space Delimited Field - Problems


Using DelimitedSplit8k against a Space Delimited Field - Problems

Author
Message
james.rosser
james.rosser
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 19
Hi All - I came across Jeff Moden's Splitter Code earlier today and have been trying to run the function against a space delimited field in my database. When running the function against the function does not seem to recognize the space as a delimiting character.


Sample Data

CoreID ComputerID ResultsText
1 1456 192.168.1.1 192.168.1.2 192.168.1.3
2 1458 192.168.1.8 192.168.1.6 192.168.1.5



Here is what I am running against this table:


Select sd.CoreID, sd.ComputerID, sd.ResultsText
From SampleData sd
cross apply dbo.DelimitedSplit8k(sd.ResultsText, ' ')



Additionally I have tried the following and it did not work either:


Select sd.CoreID, sd.ComputerID, sd.ResultsText
From SampleData sd
cross apply dbo.DelimitedSplit8k(sd.ResultsText, SPACE(1))



The output that results from both of these is below (as you can see it is not splitting out the field at all):


CoreID ComputerID ResultsText ItemNumber Item
1 1456 192.168.1.1 192.168.1.2 192.168.1.3 1 192.168.1.1 192.168.1.2 192.168.1.3
2 1458 192.168.1.8 192.168.1.6 192.168.1.5 1 192.168.1.8 192.168.1.6 192.168.1.5



Any help would be greatly appreciated. Not sure what is not working here....
Luis Cazares
Luis Cazares
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16387 Visits: 19076
You might have a character that might not be a space.
You can check which character is with this code (it's untested, but it should work).
WITH E1(N) AS (
SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL
SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL
SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1
), --10E+1 or 10 rows
E2(N) AS (SELECT 1 FROM E1 a, E1 b), --10E+2 or 100 rows
cteTally(N) AS (
SELECT ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) FROM E2
)
SELECT SUBSTRING(ResultsText, N, 1), ASCII(SUBSTRING(ResultsText, N, 1))
FROM SampleData
CROSS JOIN cteTally
ORDER BY ResultsText, N




Luis C.
General Disclaimer:
Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?


How to post data/code on a forum to get the best help: Option 1 / Option 2
james.rosser
james.rosser
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 19
Luis Cazares (7/24/2013)
You might have a character that might not be a space.
You can check which character is with this code (it's untested, but it should work).
WITH E1(N) AS (
SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL
SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL
SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1
), --10E+1 or 10 rows
E2(N) AS (SELECT 1 FROM E1 a, E1 b), --10E+2 or 100 rows
cteTally(N) AS (
SELECT ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) FROM E2
)
SELECT SUBSTRING(ResultsText, N, 1), ASCII(SUBSTRING(ResultsText, N, 1))
FROM SampleData
CROSS JOIN cteTally
ORDER BY ResultsText, N



States that it is a line feed - ASCII 10.

I tried this:


Select sd.CoreID, sd.ComputerID, sd.ResultsText
From SampleData sd
cross apply dbo.DelimitedSplit8k(sd.ResultsText, ascii(10))



Still is a no go. Get's the same result as I previously did.
james.rosser
james.rosser
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 19
Resolved it myself whoops! This works:


Select sd.CoreID, sd.ComputerID, sd.ResultsText
From SampleData sd
cross apply dbo.DelimitedSplit8k(sd.ResultsText, char(10))



Thanks Luis!
Luis Cazares
Luis Cazares
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16387 Visits: 19076
You're welcome. I'm glad I could help :-)


Luis C.
General Disclaimer:
Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?


How to post data/code on a forum to get the best help: Option 1 / Option 2
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)

Group: General Forum Members
Points: 85390 Visits: 41078
james.rosser (7/24/2013)
Resolved it myself whoops! This works:


Select sd.CoreID, sd.ComputerID, sd.ResultsText
From SampleData sd
cross apply dbo.DelimitedSplit8k(sd.ResultsText, char(10))



Thanks Luis!


I don't see where you're actually using anything from the function. Are you sue it's doing what you want?

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
james.rosser
james.rosser
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 19
It is working like a champ and doing what it needs to do. Thanks for checking in.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search