February 25, 2016 at 8:05 am
Hi,
I have a column with a string longer than life. 🙁
I need to take a specific part of it, I know the is the start and where is the end.
The problem is that each string has a different size, so I cannot determinate the length :w00t:
so every time i try to use the substring, i get different results cause i am not calculating the correct size.
for example I have the following text.
Learn from yesterday, live for today, hope for tomorrow. The important thing is not to stop questioning.
I would like to take all the text since yesterday till tomorrow. but the size of the string might change in each row.
:blush: help please
thanks
February 25, 2016 at 8:12 am
When eyeballing the data, how do you know where the start and end are? Is there any logic that can be applied to every single row? E.g everything after the second space, everything after the word 'yesterday'.
Also, you can determine the length using LEN(colname) if that's all you're missing.
February 25, 2016 at 8:17 am
Maybe something like this:
SELECT String,
SUBSTRING( String, CHARINDEX('yesterday', String), CHARINDEX('tomorrow', String) - CHARINDEX('yesterday', String) + 8 /*LEN('tomorrow')*/)
FROM(VALUES('Learn from yesterday, live for today, hope for tomorrow. The important thing is not to stop questioning.'))x(String);
As tindog mentioned, the important thing is to know how will you delimit the start and length of the string.
February 25, 2016 at 8:39 am
thanks!!!! :kiss:
it worked
February 25, 2016 at 8:51 am
astrid 69000 (2/25/2016)
thanks!!!! :kiss:it worked
The question now is... do you understand it well enough to both maintain it and do it again for something else?
--Jeff Moden
Change is inevitable... Change for the better is not.
February 25, 2016 at 9:58 am
yes, i do, cause it was similar to what i had and i was missing what length to count.
i do check 😉
thanks again 🙂
February 25, 2016 at 10:47 am
astrid 69000 (2/25/2016)
yes, i do, cause it was similar to what i had and i was missing what length to count.i do check 😉
thanks again 🙂
You bet and thank you for the feedback. From the "other" recent post of yours, you really seem to be interested in T-SQL and just wanted to make sure you understood.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply