I am new to Teradata and trying to figure out how to do a NOT LIKE statement with multiple wildcards. I've tried several different ways, but haven't found a way that works. Most recently I've tried the code below.
WHERE DIAG_CD NOT IN ALL ('S060%','S340%')
Any help you all can provide would be much appreciated.
Thanks!
You are on the right track. You can use ANY / ALL quantifier with LIKE or NOT LIKE.
WHERE DIAG_CD NOT LIKE ALL ('S060%','S340%')
or
WHERE NOT (DIAG_CD LIKE ANY ('S060%','S340%'))
IN does not support wildcards. You need to repeat the conditions:
where diag_cd not like 'S060%' and diag_cd not like 'S340%'
Or you can do regex matching instead: ^ represents the beginning of the string, and | stands for or. This syntax is easier to extend with more strings patterns.
where not regexp_like(diag_cd, '(^S060)|(^S340)')
Related
i have a data with entrance_page_name:
/search?q=
/search?
/search?ast
can i get the data with the similar first word
WHEN REGEXP_CONTAINS(entrance_page_name, '^/search/q=') THEN 'search?q='
WHEN REGEXP_CONTAINS(entrance_page_name, '^search?') THEN 'search?'
But it's not really works. Any assistance with this would be greatly appreciated!
Thank you
You can possibly use the raw string, and an escape character to override ? symbol.
SELECT CASE WHEN REGEXP_CONTAINS('/search?q=SDbmoLZK89s', r'^/search\?q=') THEN 'search?q=' END as test
The above code should ideally work in your situation.
I would like to extract an ID (a number) from a bunch of URLs in Redshift. I know I can use regexp_substr for this purpose, but my knowledge of regular expressions is weak. Here are a couple example URLs:
/checkout?feature=ADVANCED_SEARCH&upgradeRedirect=%2Fmentions%3Ftop_ids%3D1222874068&btv=feature_ADVANCED_SEARCH
/checkout?feature=ADVANCED_SEARCH&trigger=mentioning-author-rw&upgradeRedirect=%2Fmentions%3Ftop_ids%3D160447990
After parsing the above URLs, I would like the output to be:
1222874068
160447990
Note that the parameter top_ids remains constant and will help break the URL.
I tried using multiple versions of split_part as well. But there may be variations in the URL where it might break. So using a regular expression may be a better idea.
Any help would be greatly appreciated.
You can use:
select regexp_substr(column,'top_ids%3D([0-9]*)', 1, 1, 'e')
The 'e' extracts the substring in (brackets).
Try something like this:
SUBSTR(REGEXP_SUBSTR(yourcolumn, 'top_ids%3D([0-9]{2,})'), 11, 20)
Just looking for 'top_ids%3D' and 2 or more digits after it.
Then removes the first 10 characters.
I have strings which contain numbers like that:
a20cdac0_19221bdc12022bab3fe05a43df4a7dbe
I need to get only symbols after underscore symbol:
19221bdc12022bab3fe05a43df4a7dbe
Unfortunately, the amount of those symbols is always different, so I can't use just RIGHT function.
I know that probably REGEXP might help, but I can't understand how to use that exactly. Will be very grateful for the help.
Below is for BigQuery Standard SQL (using regexp)
regexp_extract(value, r'_(.*)') regexp_approach
if to apply to sample value from your question
regexp_extract('a20cdac0_19221bdc12022bab3fe05a43df4a7dbe', r'_(.*)') regexp_approach
result is
Yet, another regexp option is to use regexp_replace as in below example
regexp_replace(value, r'^.*?_', '')
Note: using split in this case is also an option unless you have more than one _ in which case you will get part between first and second _
split(value, '_')[safe_offset(1)]
Also, as you can see you need to use safe to prevent error in cases when _ is absent
You can use the split function like this
select split('a20cdac0_19221bdc12022bab3fe05a43df4a7dbe','_')[ORDINAL(2)];
https://cloud.google.com/bigquery/docs/reference/standard-sql/string_functions#split
I tried to use difflib to get_close_matches in a tuple data...but it does not work...I have earlier used difflib in a JSON file but couldn't use it in an SQL...Result expectationI want to find words similar to the input given..even if there is any spelling mistake...for example...if the input is treeeee or TREEEEE or Treeea...my program should consider the nearest match...that is a tree...Similar to the Did you mean? function in GOOGLE. I also tried SELECT * FROM Dictionary WHERE Expression LIKE '%s but the problem persists. Please help me solve this. Thanks in advance.
SQL functions Soundex and DIFFERENCE look like the closest fit.
Is it possible to do String comparison where one of the strings I am comparing against has wild cards and is generally just for formatting purposes. For example
Dim correctFormat as String = "##-##-###-##"
Dim stringToCheck = someClass.SomeFunctionThatReturnsAStringToCheck
If FormatOf(CorrectFormat) = FormatOF(StringToCheck) then
Else
End if
I am aware of the made up FormatOf syntax, but I'm just using it to show what I am asking.
No need for regular expressions.
You can simply use the Like operator, which supports ?, * and # as wildcards and also character lists ([...], [!...])
So you simply change your code to:
If stringToCheck Like correctFormat Then
and it will work as expected.
The way is to use regular expressions - that's what they are for.
This is the regular expression that matches the format you have posted:
^\d{2}-\d{2}-\d{3}-\d{2}$
As the previous post mentioned, you should use regular expressions for that purpose - they are way better for that task.
Sadly, learning them can be confusing, especially finding bugs can be really annoying.
I really like http://www.regular-expressions.info/ and http://regexpal.com/ for building and testing regexes before.
In VB.net use something like reg.ismatch