How do I go about display the values or figuring out what the delimiter. I need to break a part the string into individual fields.
Thanks.
November 10, 2022 at 6:14 pm
You don't know the delimiter? It's not predefined/standardized?
STRING_SPLIT function is available in 2016, but would require nvarchar instead of ntext.
ntext has been deprecated since SQL Server 2008, & has limitations -- can you convert to nvarchar?
Are the values unicode? Do the values exceed 4000 characters?
November 10, 2022 at 6:51 pm
Not a standard delimiter ...
If I can find the delimiter any code I can use to parse the data?
November 11, 2022 at 1:45 am
I was able to convert field. I copied table to a 2016 box.
STRING_SPLIT function is available in 2016, but would require nvarchar instead of ntext.
Looks like they are using more than 1 value for delimiter..
any suggestions?
November 11, 2022 at 5:30 am
--Jeff Moden
Change is inevitable... Change for the better is not.
November 11, 2022 at 11:42 am
Read the NTEXT into an NVARCHAR(MAX). --> done
It appears that they used 3 characters to delineate the data --> |++
Use a Tally table function to read each character. If it's not the letters A-Z or a-z or 0-9 or common symbols, then it must be a delimiter. Capture that and use it as a delimiter for String_Split.
-- Can I still do this with the 3 character delimiter? Not sure how to do that using String_Split.
Thx.
November 11, 2022 at 12:51 pm
I am pretty sure you have heard of the word "replace" - use it to replace those 3 chars with another single delimiter that is not used within the text.
and do not use the native string_split - slow and does not return the ordinal of the strings.
search the forums here for the delimitedsplit function that would work faster.
November 11, 2022 at 1:44 pm
select cast(replace(cast(body as nvarchar(max)),'???','?') as ntext)
from lookuptable2
where
description like '???%'
I used this template and can see that it did indeed did do the replace, but how do I capture individual fields...
November 11, 2022 at 4:16 pm
do not use the native string_split - slow and does not return the ordinal of the strings.
Funny thing there... I've never actually tested it for performance because I never use it just because of the missing ordinal thing.
[EDIT} Ah... now I remember why I've not tested it for performance. Wayne Sheffield tested it way back when. Here's his article on that subject.
https://www.sqlservercentral.com/articles/splitting-strings-in-sql-server-2016
--Jeff Moden
Change is inevitable... Change for the better is not.
November 11, 2022 at 4:23 pm
select cast(replace(cast(body as nvarchar(max)),'???','?') as ntext) from lookuptable2 where description like '???%'
I used this template and can see that it did indeed did do the replace, but how do I capture individual fields...
select cast(replace(cast(body as nvarchar(max)),'???','?') as ntext) from lookuptable2 where description like '???%'
I used this template and can see that it did indeed did do the replace, but how do I capture individual fields...
Why the REPLACE??? Are you now saying that you know what the delimiter is?
[EDIT] Ah... I missed your other post about the 3 character delimiters and now understand the reason for needing REPLACE
And, to answer the second question there... you've already been told... use a String_Splitter with the delimiter that you've found.
And, remember, we can't see your data so you're pretty much on your own there.
To repeat the steps I laid out...
1. Read the NTEXT into an NVARCHAR(MAX).
2. Use a Tally table function to read each character. If it's not the letters A-Z or a-z or 0-9 or common symbols, then it must be a delimiter. Capture that and use it as a delimiter for String_Split.
While String_Split may be slow ((something I've not confirmed before)) and it has no elemental ordinal in the return, you've not stated that you need to have any sense of order in the "fields" that you return.
--Jeff Moden
Change is inevitable... Change for the better is not.
November 11, 2022 at 4:34 pm
frederico_fonseca wrote:
do not use the native string_split - slow and does not return the ordinal of the strings.
Aaron Bertrand's tests from 2016 showed exceptionally good performance: https://sqlperformance.com/2016/03/sql-server-2016/string-split
November 11, 2022 at 5:42 pm
Sample data in field:
PartNbr|#@|Machine|#@| ttxx23|#@|plc1|#@| ttxx24|#@|plc2
So it looks like PartNbr|#@|Machine| -- these are the fields
Then | ttxx23| -- when it sees a space data starts
partnbr Machine
ttxx23 plc1
ttxx24 plc2
any suggestions
November 11, 2022 at 6:17 pm
Sample data in field:
PartNbr|#@|Machine|#@| ttxx23|#@|plc1|#@| ttxx24|#@|plc2
So it looks like PartNbr|#@|Machine| -- these are the fields Then | ttxx23| -- when it sees a space data starts
partnbr Machine ttxx23 plc1 ttxx24 plc2
any suggestions
Sorry... no. I give up.
--Jeff Moden
Change is inevitable... Change for the better is not.
November 11, 2022 at 7:00 pm
Use delimited split using pipe as delimiter and then use MOD to select 1st and 3rd items
Far away is close at hand in the images of elsewhere.
Anon.
November 11, 2022 at 7:15 pm
could you send a sample of that code?
Thx.
Viewing 15 posts - 1 through 15 (of 27 total)
You must be logged in to reply to this topic. Login to reply