Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
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 6, 2016 8:09 AM
Points: 4, Visits: 15
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


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 9:43 AM
Points: 7,821, Visits: 16,885
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
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 6, 2016 8:09 AM
Points: 4, Visits: 15
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 6, 2016 8:09 AM
Points: 4, Visits: 15
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


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 9:43 AM
Points: 7,821, Visits: 16,885
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
Post #1477278
Posted Wednesday, July 24, 2013 8:48 PM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 1:47 PM
Points: 41,426, Visits: 38,755
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."

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 6, 2016 8:09 AM
Points: 4, Visits: 15
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