June 17, 2015 at 7:28 am
Can it be possible to split the below string to NICK and SERVERS. Query which provides two columns, first column data should be NICK and other SERVERS.
_BF-TYPE:NICK_ _BF-SUBSYSTEM:SERVERS_
June 17, 2015 at 7:39 am
Sanz (6/17/2015)
Can it be possible to split the below string to NICK and SERVERS. Query which provides two columns, first column data should be NICK and other SERVERS._BF-TYPE:NICK_ _BF-SUBSYSTEM:SERVERS_
Sure it is possible. Just using substring and charindex.
My guess is there needs to be some rules about how you parse this out. Do the actual values have a pattern that is 100% consistent?
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
June 17, 2015 at 7:50 am
The patterns are consistent. Length of NICK and SERVERS can vary..
June 17, 2015 at 8:01 am
Sanz (6/17/2015)
The patterns are consistent. Length of NICK and SERVERS can vary..
What have you tried so far?
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
June 17, 2015 at 8:36 am
Sanz (6/17/2015)
The patterns are consistent. Length of NICK and SERVERS can vary..
Are you going to post up a few examples or keep Sean guessing?
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
June 17, 2015 at 8:56 am
ChrisM@Work (6/17/2015)
Sanz (6/17/2015)
The patterns are consistent. Length of NICK and SERVERS can vary..Are you going to post up a few examples or keep Sean guessing?
Haha Chris. I am not guessing. I figure if it isn't important to the OP then I am not going to bother wasting any effort either. 😉
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
June 17, 2015 at 9:06 am
Maybe the force is strong with this one. 😛
Here is a shot in the dark. If this doesn't help, you will need to provide more information.
with TestData as (
select TestStr from (values ('_BF-TYPE:NICK_ _BF-SUBSYSTEM:SERVERS_'))dt(TestStr)
)
select
--charindex('_BF-TYPE:',TestStr) + 9,
--charindex('_BF-SUBSYSTEM:',TestStr) + 14,
--charindex('_',@TestStr,charindex('_BF-TYPE:',TestStr) + 9),
substring(TestStr,charindex('_BF-TYPE:',TestStr) + 9,(charindex('_',TestStr,charindex('_BF-TYPE:',TestStr) + 9)) - (charindex('_BF-TYPE:',TestStr) + 9)),
substring(TestStr,charindex('_BF-SUBSYSTEM:',TestStr) + 14,(charindex('_',TestStr,charindex('_BF-SUBSYSTEM:',TestStr) + 14)) - (charindex('_BF-SUBSYSTEM:',TestStr) + 14))
from
TestData;
June 17, 2015 at 9:09 am
There is no need to guess. Here are few more examples.
_BF-TYPE:NICK_ _BF-SUBSYSTEM:SERVERS_
_BF-TYPE:CONFIG_ _BF-SUBSYSTEM:CARRIER_
_BF-TYPE:INSERT_ _BF-SUBSYSTEM:CARRIERS_
June 17, 2015 at 9:16 am
Sanz (6/17/2015)
There is no need to guess. Here are few more examples._BF-TYPE:NICK_ _BF-SUBSYSTEM:SERVERS_
_BF-TYPE:CONFIG_ _BF-SUBSYSTEM:CARRIER_
_BF-TYPE:INSERT_ _BF-SUBSYSTEM:CARRIERS_
Still looks like the code works:
with TestData as (
select TestStr from (values ('_BF-TYPE:NICK_ _BF-SUBSYSTEM:SERVERS_'),('_BF-TYPE:CONFIG_ _BF-SUBSYSTEM:CARRIER_'),('_BF-TYPE:INSERT_ _BF-SUBSYSTEM:CARRIERS_'))dt(TestStr)
)
select
--charindex('_BF-TYPE:',TestStr) + 9,
--charindex('_BF-SUBSYSTEM:',TestStr) + 14,
--charindex('_',@TestStr,charindex('_BF-TYPE:',TestStr) + 9),
substring(TestStr,charindex('_BF-TYPE:',TestStr) + 9,(charindex('_',TestStr,charindex('_BF-TYPE:',TestStr) + 9)) - (charindex('_BF-TYPE:',TestStr) + 9)),
substring(TestStr,charindex('_BF-SUBSYSTEM:',TestStr) + 14,(charindex('_',TestStr,charindex('_BF-SUBSYSTEM:',TestStr) + 14)) - (charindex('_BF-SUBSYSTEM:',TestStr) + 14))
from
TestData;
June 17, 2015 at 9:24 am
Thanks.
June 17, 2015 at 9:27 am
Sanz (6/17/2015)
Thanks.
Now, explain how it works. You will have to support this code.
Viewing 11 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply