Teradata SQL Regex Question - Extract Numeric values after an Alpha - sql

I am trying to run a select statement on a table acct id. My account ID's can have the following pattern which is the one I am having issues with: 2733R9087813964
How do I run a SELECT Statement on this column and extract only the numeric portion after the "R"?
So the result in this scenario would be: 9087813964
Any help would be appreciated.

try
SELECT Substr(ACC_ID, Position('R' IN ACC_ID) +1 )
FROM ACCOUNT

Related

How I can use where Condition in SQL I have comma separated value in A columns in multiple rows

Column1 EventTypes_pKey
Are 5,3
Test 1,4,5
test 1,3,5
If I am using
Select * from Table name where EventTypes_pKey in('5,1,4)
then I want that record where these value belongs the column.
How I can use where condition on the basis of EventTypes_pKey this is my Varchar column.
I want If I am selecting 5,3,4 the there should be all three row data.
Please help me.
If you are using Postgres, you can do this by by converting the value into an array and then using the overlaps operator &&
select *
from badly_designed_table
where string_to_array(eventtypes_pkey, ',')::int[] && array[5,3,4];
Online example

Query to find results starting with a number or higher - SQL Server

Example: http://sqlfiddle.com/#!18/7f3df/2
CREATE TABLE Table1 (
Reg uniqueidentifier
);
INSERT INTO Table1 (Reg)
Values
('DF215E10-8BD4-4401-B2DC-99BB03135F2E'),
('93015E10-8BD4-4401-B2DC-99BB03135F2E'),
('21215E10-8BD4-4401-B2DC-99BB03135F2E');
Query:
select * from Table1
WHERE left(CAST(Reg AS CHAR(36)),1) > 8
I need to create a query that finds all results that start with either a number 8 or higher or starts with a letter but i am getting a conversion error i cant find a fix for. The column is a uniqueidentifier. How can i cast this to something i can filter on?
Can anyone give some advice on a solution to this?
Thanks
You need to do the comparison using strings:
convert(varchar(36), newid()) like '[89ABCDEF]%'
You may use SQL Server's enhanced LIKE here, which has some basic regex support:
SELECT *
FROM table1
WHERE Reg LIKE '[89A-Z]%';
The pattern [89A-Z]% says to match a starting 8 or 9, or any letter.

SQL Query to pull rows starting with a certain 3 digits

I have a numbers column in my sql table and I want to pull all the numbers that start with 3 specific digits; how would I query this?
Use the "LIKE" query:
123 is the prefix. I think you have to store the numbers as strings though, just try it out on your data set :-)
SELECT * from TableName Where ColumnName LIKE '123%'
See also this Q&A: In MySql, find strings with a given prefix

Counting Values in a repeated field in BigQuery

I want to select rows that have more thank k values in a repeated field. (consider for example selecting user that have more than 3 email addresses)
In Standard SQL I know I can use
SELECT * FROM dataset.users
WHERE array_length(email_address) > 3
But what is the way to do this in BigQuery legacy SQL?
No need for a subquery; you should be able to filter with OMIT RECORD IF directly:
SELECT *
FROM dataset.users
OMIT RECORD IF COUNT(email_address) <= 3;
Do you mind commenting on why you want to use legacy SQL, though? If you encountered a problem with standard SQL I'd like to understand what it was so that we can fix it. Thanks!
Counting Values in a repeated field in BigQuery
BigQuery Legacy SQL
SELECT COUNT(email_address) WITHIN RECORD AS address_count
FROM [dataset.users]
If you want then to count output rows - you can use below
SELECT COUNT(1) AS rows_count
FROM (
SELECT COUNT(email_address) WITHIN RECORD AS address_count
FROM [dataset.users]
)
WHERE address_count> 3

select single value into multi rows oracle sql

I want to select one value and retrieve it into multi rows i tried to search about this case but i didn't find the write way to sole it and
and finaly sorry for my English
try select your_value, t.* from table t