May 6, 2016 at 11:26 am
I would like to remove value after Arthritis;
substring(Summaryline, 1, charindex(',',Summaryline) - 1) [Extremity Quadrant],
substring(Summaryline, charindex(':',Summaryline) +1, len(Summaryline) - charindex(';',Summaryline)) [Clinical Info for Radiologist],
substring(Summaryline, charindex(';',Summaryline) +30, 255) [Additional Info to DI Tech]
Extremity QuadrantClinical Info for Radiologist Additional Info to DI Tech
Upper Left Arthritis; Additional Info to DI Tech:TES TEST for Query
May 6, 2016 at 11:33 am
Just Arthritis? After the semicolon perhaps? This is easy to do but I don't want to give you a bad solution. Please provide sample data and how you expect it to look like.
This looks like free text...
Extremity Quadrant Clinical Info for Radiologist Additional Info to DI Tech
Upper Left Arthritis; Additional Info to DI Tech:TES TEST for Query
Trying to parse that out accurately and consistently may be an issue unless you have a guaranteed text/symbol that you can use.
May 6, 2016 at 11:41 am
Yes, after the semi column . .
May 6, 2016 at 12:06 pm
Here is a simple example on how to grab ALL text before the semicolon. Just keep in mind this implies that there will always be a semicolon to use as a separator.
DECLARE @myTable TABLE (strings VARCHAR(100))
INSERT INTO @myTable
VALUES ('blah, blah blah; more stuff'), ('some text before; some text after'), ('yet another example; with a semicolon')
SELECT
SUBSTRING(strings, 1, CHARINDEX(';', strings) -1)
strings
FROM
@myTable
May 6, 2016 at 12:37 pm
The column Summaryline has the value like this varchar(2000)
Upper Right, Clinical Info for Radiologist: Bone Tumor; Additional Info to DI Tech: xxx please check
I need to get this to 3 different columns
Upper Right (c0lumn1) Bone Tumor (column2) xxxplease check (column 3)
May 6, 2016 at 12:39 pm
If you need to split a single column into three different ones based on a 1-character delimiter, your best bet is probably DelimitedSplit8K function.
The second link in my signature has an article with the function and details about how it works. It's well worth the read.
May 6, 2016 at 12:45 pm
It wont work for me as my shop does not support . . 🙁
May 6, 2016 at 12:49 pm
jollyegeorge (5/6/2016)
It wont work for me as my shop does not support . . 🙁
I don't get what you mean. Your shop does not support what?
May 6, 2016 at 12:54 pm
does every summaryline include the text that is in bold below?
Upper Right, Clinical Info for Radiologist: Bone Tumor; Additional Info to DI Tech: xxx please check
if so...maybe think about doing a replace with NULL before using delimitted splitter
I think it maybe best if you analyse ALL variations of the summary line to determine what is really required.
Are you able to get to the source data that create the "summaryline"....it would probably be easier to do what you want from there
________________________________________________________________
you can lead a user to data....but you cannot make them think
and remember....every day is a school day
May 6, 2016 at 12:57 pm
I get error for 'Invalid object name 'dbo.DelimitedSplit8K'
Yes it does, all the summary line has these bold values.
May 6, 2016 at 1:05 pm
jollyegeorge (5/6/2016)
I get error for 'Invalid object name 'dbo.DelimitedSplit8K'Yes it does, all the summary line has these bold values.
It's a custom function that you have to create on your system before you can use it.
May 6, 2016 at 1:08 pm
as Ed tried to tell you...
http://www.sqlservercentral.com/articles/Tally+Table/72993/
code is at bottom of this article.....strongly suggest you read the article and the associated discussion thread
________________________________________________________________
you can lead a user to data....but you cannot make them think
and remember....every day is a school day
May 6, 2016 at 7:01 pm
jollyegeorge (5/6/2016)
I get error for 'Invalid object name 'dbo.DelimitedSplit8K'Yes it does, all the summary line has these bold values.
DelimitedSplit8K is not built in, you need to create it. For the code to create DelimitedSplit8K, see the link in my signature for a string splitter (or Ed's) as we both have links to the same article.
Edit: apologies for repeating what everyone already said, I did not realize there was a page 2 in this thread.
-- Itzik Ben-Gan 2001
May 9, 2016 at 5:41 am
OP, there's a lot of good stuff in that article. I know it isn't short and can, if you aren't used to it, twist the way you think, but it's well worth the time to read it. It can really change your expectations of performance.
Viewing 14 posts - 1 through 13 (of 13 total)
You must be logged in to reply to this topic. Login to reply