Teradata Character Column with non alphabet values - sql

I have a name column in Teradata that has customer full name all in one column. There are some names with -,_,.,/,#,! in between the name characters. I want to be able to pull records where there are names with these conditions. Is there a better option to pull records with the scenario below?
Currently, I am writing query like this
SELECT NAME FROM TABLESOURCE WHERE NAME LIKE ANY('%-%','%.%','%#%','%~%','%!%')
Thanks in advance.

I haven't tested this but I think you could test for equality when those characters are removed from the name using otranslate
select name
from tablesource
where name <> otranslate(name,'-.#~!','')

Related

How to match a regular expression from a SQL table to a text

I have used before LIKE command to match patterns to a specific SQL table column. For example need all the rows which all have name started with "A". But this case I am trying to solve things reversed , have a column "Description" where all the regular expressions row wise. And need to return specific rows which all match with a input text.
Table A
Description
============
\b[0-9A-Z ]*WT[A-Z0-9 ]*BALL\b
\b[0-9A-Z ]*WG[A-Z0-9 ]*BAT\b
\b[0-9A-Z ]*AX[A-Z0-9 ]*BAR\b
So Description column has these regular expressions and the input text "BKP 200 WT STAR BALL" So need to return the first row after select query since that the only match. If any one can help with the select query or idea, would be very helpful. If more details required please mention also.
Cross join you regex table to one that you searching within. Then just match two columns against each other.
Here's the example how you can match any of your expressions.
Here how you can match all of them

SQL select statement dout

I have a table in which it contains the Name column contains some names in Capital letters and some data is in small letters in my WHERE clause if i give (where name='Syed') it will give only matching records because it is case sensitive but i want my output should display like(SYED,Syed,syed) how to do that please help me
SELECT Name
FROM Persons
WHERE UPPER(Name) = 'SYED'
This will return the Name in whatever case it exists as in the table, but will return all instances of it.

SQL - just view the description for explanation

I would like to ask if it is possible to do this:
For example the search string is '009' -> (consider the digits as string)
is it possible to have a query that will return any occurrences of this on the database not considering the order.
for this example it will return
'009'
'090'
'900'
given these exists on the database. thanks!!!!
Use the Like operator.
For Example :-
SELECT Marks FROM Report WHERE Marks LIKE '%009%' OR '%090%' OR '%900%'
Split the string into individual characters, select all rows containing the first character and put them in a temporary table, then select all rows from the temporary table that contain the second character and put these in a temporary table, then select all rows from that temporary table that contain the third character.
Of course, there are probably many ways to optimize this, but I see no reason why it would not be possible to make a query like that work.
It can not be achieved in a straight forward way as there is no sort() function for a particular value like there is lower(), upper() functions.
But there is some workarounds like -
Suppose you are running query for COL A, maintain another column SORTED_A where from application level you keep the sorted value of COL A
Then when you execute query - sort the searchToken and run select query with matching sorted searchToken with the SORTED_A column

Delete rows if letters in cell SQL Server

I needed some guidance as to how I can exlude rows that contains any form of letter in a cell that is supposed to contain integers only.
This is what the data looks like now:
CustomerID
----------
ea176680
27906857
62675436
62566247
1bed413e
61110053
61113323
34441416
AS you can see in the table, the first,ID contains letters. How can I remove complete rows if a cell were to contain any form of letters?
How about this where clause?
where CustomerId not like '%[^0-9]%'
It filters out any values that have a non-digit. Unfortunately, SQL Server doesn't support regular expressions, but this will do what you want.
If you specifically wanted to look for letters, you can do:
where CustomerId like '%[a-zA-Z]%'
SQL Server can match on a specific pattern in your statement using like. It looks somewhat like regex, but isn't exactly that.
Use this statement if you want to match on all CustomerIds that contains characters in the range A-Z and a-z:
select *
from table
where CustomerID like '%[A-za-z]%'

Find out if a value exists in a column with a large input values set

What is the most effective (and simple) way to find out if a specific column cells of a table contain one of a given values?
To give you some background, I have a list of 1000 ID numbers. They might or might not exist in a "FileName" column of a table "ProcessedFiles" as a part of the filename.
Basically, I need to check which of these 1000 tasks have been processed (i.e. they exist in the table).
The thing that I came with seems very uneffective:
SELECT * FROM ProcessedFiles
WHERE FileName LIKE '%54332423%'
OR FileName LIKE '%234432%'
OR FileName LIKE '%342342%'
...
etc
Thanks for help!
You could create a temporary table and insert all the Ids in a column. Then you could cross join with the ProcessedFiles table and check for the id in the name with a like:
SELECT pf.*
FROM ProcessedFiles pf,table t
WHERE pf.FileName like '%'+t.Id+'%'
I tested the above and it worked on SQL Server.