Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Using DelimitedSplit8k against a Space Delimited Field - Problems Expand / Collapse
Author
Message
Posted Wednesday, July 24, 2013 2:14 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, July 23, 2014 10:54 AM
Points: 4, Visits: 8
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....
Post #1477262
Posted Wednesday, July 24, 2013 2:21 PM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Yesterday @ 4:26 PM
Points: 3,535, Visits: 7,620
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.
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?

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1477264
Posted Wednesday, July 24, 2013 2:39 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, July 23, 2014 10:54 AM
Points: 4, Visits: 8
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.
Post #1477273
Posted Wednesday, July 24, 2013 2:40 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, July 23, 2014 10:54 AM
Points: 4, Visits: 8
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!
Post #1477274
Posted Wednesday, July 24, 2013 2:48 PM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Yesterday @ 4:26 PM
Points: 3,535, Visits: 7,620
You're welcome. I'm glad I could help


Luis C.
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?

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1477278
Posted Wednesday, July 24, 2013 8:48 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 1:13 AM
Points: 36,978, Visits: 31,499
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."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1477331
Posted Thursday, July 25, 2013 6:36 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, July 23, 2014 10:54 AM
Points: 4, Visits: 8
It is working like a champ and doing what it needs to do. Thanks for checking in.
Post #1477455
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse