I have values that look like this:
D:\DM-250\Insert_Jobs-QA-UAT\14-FILE_A_UpdateInsert.dts
D:\DM-250\Insert_Jobs-QA-UAT\Something_DaisyChain\14-stuff_and_things_UpdateInsert.dts
D:\DM-250\14-another_file.dts
I want the very ends of these 3 values, starting from the last "\" character.
I tried to use FINDSTRING, but I don't know how to grab the last occurrence of a character.
Any suggestions?
This will give you the position from the right.
findstring(reverse([your column]),"\",1)
I am guessing you are trying to extract filename which is:
right([your column], [result from above] - 1)
Related
I am trying to pull the data from between 2 string points in mysql, my example script would be
'otherdata&p1=textneeded&otherdata'
I need to pull the "textneeded" bit, "P1=" is the start position and will only appear once within the string but the "&" sign can appear multiples times. If there is nothing between these 2 points just return a blank. Where I have put otherdata, this can be a varying number of things on either end of the points I am trying to extract the data from. I am no expert at all on mysql so any help would be appreciated.
Thanks
You may use MySQL's locate() function to get the position of p1= substring and then the position of the next & and use substr() to extract the string between the two. +3 and -3 are to compensate for the length of p1=:
set #s='otherdata&p1=textneeded&otherdata';
select substr(#s,locate('p1=',#s)+3,locate('&',#s,locate('p1=',#s))-locate('p1=',#s)-3)
currently I'm making something.
using (var IDatabaseQuery = Lightningbolt.GetDatabaseManager().CreateQueryObject())
{
IDatabaseQuery.SetQuery("SELECT * FROM catalogue_baseitems WHERE name LIKE '%hc2_%' OR name LIKE '%hc3_';");
data = IDatabaseQuery.FetchTable();
}
That's what I use, I want to get all the items beginning with hc2_ and hc3_, however, I only get the items starting with hc2_. In the SQL contains also items starting with hc3_ but it doesn't show while executing the query. What do I wrong?
If you want items beginning with hc2_ or hc3_, you need to make two changes:
Don't use the % at the beginning, and
Escape the underscore because it masks to "any one character"
Try something like this:
SELECT * FROM catalogue_baseitems WHERE name LIKE 'hc2\_%' OR name LIKE 'hc3\_%'
Note that %hc2_% will match any of the following examples:
abchc2X (because of the leading % and the underscore will match the X)
hc23 (because underscore will match the 3)
... and so on
You are missing the second percent sign: '%hc3_%'
You want result which contains hc2_ and hc3_ at the beginning then you need to use clause like this 'hc2_%' or hc3_%.
You are getting results for hc2_ because you are using '%hc2_%', this return any string which contains hc2_ anywhere in the string.
Change your query to this
IDatabaseQuery.SetQuery("SELECT * FROM catalogue_baseitems WHERE name LIKE 'hc2\_%' OR name LIKE 'hc3\_%';");
and don't forgot about underscore(_), this is a wildcard character.
I have got field containing comma separated values. I need to extract the last element in the list.
I have tried with this:
select list_field, LTRIM(RTRIM(right(list_field, len(list_field) - CHARINDEX(',',list_field))))
But it returns the last part of the list just starting after the first comma occurrence.
For example,
a,b returns b
a,b,c returns b,c
I would like to use a regex like pattern. Is it possible in TSQL (sql server 2008)?
Any other clues?
Find the last , by reversing the string and looking for the first occurrence, then read that many characters from the right of the string;
rtrim(right(list_field, charindex(',', reverse(list_field)) - 1))
(Use reverse(list_field) + ',' if there is the possibility of no delimiters in the field & you want the single value)
Basically I'm trying to remove a value (val2 for example) from a string that looks like 'val1,val2,val3'. However the values can be arranged in any order and I want to avoid ending up with stuff like ',val1,val3', 'val1,,val3' or 'val1,val3,'. I thought about replacing 'val2' with '' and then replacing ',,', ',end' and 'start,' with ','. But I don't know what the markers for end and start of a string are.
Storing multiple values in one single column is never a good idea. You should think about redesign your data model.
You can get what you want with regular expressions, see MYSQL documentation. There are two characters ^ and $ that match beginning and end of a string.
I am able to use LOCATE to get the index of a character such as a . in www.google.com. Thus I can use substring to strip out everything before the first ..
Is there a way I can look for the last /?
So I can get test.htm out of http://www.example.com/dev/archive/examples/test.htm?
I do not want to say the 6th slash, I want to say the last slash. Can this be done?
Use substring_index
select substring_index('http://www.example.com/dev/archive/examples/test.htm','/',-1)