Search for a long list of names in SQL - sql

I have a CSV list with a few thousand names (first, last) and I would like to search for them in SQL. How can I do this easiest?
Edit: I'm using oracle obiee so I'm somewhat limited. Not sure if I can just load a csv into a temporary table since my access is limited. Will try this tomorrow at work since I just left. Using join on it sounds quite clever to my beginner ears though.

Follow these steps
Import CSV files into your SQL server of your choice.
Use the following sql statement: select * from <table name> where <last name column> = 'smith';

I ended up doing
WHERE 'first name'||'last name'||'first name' LIKE '%john%smith%'
The first name is concatenated both at beginning and end so that it mathes both 'john smith' and 'smith john'.

Related

SQL Select As with Apostrophe

I am stuck with the following SQL line due to the apostrophe. I am using this to generate a table in Power BI that is used as the RLS link. As a result the apostrophe needs to stay in one string.
select 'adam.obrian#email.com.au' as Email, 'Adam O'Brian' as Access union all
How would I get around this?
Expecting a table as below:
Email
Access
adam.obrian#email.com
Adam O'Brian
Ignoring the Union all, this is part of a long table query.
Pleased to say I got this one sorted myself.
All it needed was a double apostrophe as below:
select 'adam.obrian#email.com.au' as Email, 'Adam O''Brian' as Access union all
Cheers

SQL Where clause from a file on Oracle

I have a requirement to construct an SQL that has a where clause which is expected to look into a file entries to be used in that clause.
SELECT DISTINCT '/',t_05.puid, ',', t_01.puid,'/', t_01.poriginal_file_name
FROM PWORKSPACEOBJECT t_02, PREF_LIST_0 t_03, PPOM_APPLICATION_OBJECT t_04, PDATASET t_05, PIMANFILE t_01
WHERE t_03.pvalu_0 = t_01.puid AND t_02.puid = t_03.puid AND t_03.puid = t_04.puid AND t_04.puid = t_05.puid AND t_02.puid IN ( 'izeVNXjf44e$yB',
'gWYRvN9044e$yB' );
The above is the SQL query. As you can see the IN clause has two different strings ( puids ) that are to be considered. But in my case, this list is like 50k entries long and would come from splunk and will be in a text file.
Sample output of the text file looks as belows:
'gWYRvN9044e$yB',
'DOZVpdOQ44e$yB',
'TlfVpdOQ44e$yB',
'wOWRehUc44e$yB',
'wyeRehUc44e$yB',
'w6URehUc44e$yB',
'wScRehUc44e$yB',
'yzXVNXjf44e$yB',
'guWRvN9044e$yB',
'QiYRehUc44e$yB',
'gycRvN9044e$yB'
I am not an SQL guru, but a quick google on this gave me a reference to OPENROWSET construct, which is not available on Oracle.
Can you please suggest some pointers on what can be done to circumvent the problem.
Thanks,
Pavan.
Consider using an external table, SQL Loader or perhaps loading the file into a table in the application layer and querying it normally.
I would recommend creating a Global Temporary table, adding the rows to that table, and then joining to your temp table.
How to create a temporary table in Oracle
Other options:
You could also use pipelined functions:
https://oracle-base.com/articles/misc/pipelined-table-functions
Or use the with as... construct to fold the data into the SQL. But that would create a long SQL statement.

SQL code for retrieving values of column starting using wildcard

I want to look for values in variable/column which start with 'S' and has 'gg' in between.
For instance Staggered is a word which starts with alphabet S and has gg in between the word.
so what sql query to write to get the result.
Due to the fact that you did not provide much meta information (which database?), I'll just show the following:
SELECT * FROM <table>
WHERE <columnname> LIKE 'S%gg%';
Good luck :)
As the target database is not mentioned, I will answer with Oracle syntax:
select *
from TABLE_NAME
where COL_NAME like 'S%gg%'

Using wildcard characters while trying to convert from one datatype to another

I'm trying to run an SQL query involving converting one datatype to another.
SELECT
convert(char(12),name) as NAME
FROM
people
WHERE
convert(char(12),place) = 'Chicago'
This works. However, I'm not sure how to alter the query to use wildcard characters. I imagine it would be something like the following (which does not work in its current state) -
SELECT
convert(char(12),name) as NAME
FROM
people
WHERE
convert(char(12),place) = '%Chicago%'
Please help.
If you want to use wildcard characters, you need to use LIKE:
select convert(char(12),name) as NAME
from people
where convert(char(12),place) LIKE '%Chicago%'

Problem select specific column name using sql statement

I found problem when trying to retrieve specific name column that using syntax/statement/command using sql.
Example I have table 'dcparam' with name some column 'SELECT', 'INSERT', 'UPDATE' in database sqlserver.
Then I trying to select using query:
SELECT SELECT,INSERT,UPDATE FROM dcparam
Well it could be solve using "*" in select, but then how if i wish only specific column.
Regard.
Add square brackets around the column name.
SELECT [SELECT], [INSERT], [UPDATE] FROM dcparam
It's probably best to reconsider your column names in the long run however...