How to Pass Comma String as Single String in IN Clause - sql

I'm writing a SQL code using an IN operator. It is working good unless I encountered some records having comma in the strings.
This is where I am failing to fetch those records.
For example -: 'Pratik,Sarangi' is a record i want to pass in the IN clause where in it reads as 2 different datas.
I am using Oracle SQL to build the query
select * from table where name in (:name)
where :name is a user input parameter.

Related

How can you filter Snowflake EXPLAIN AS TABULAR syntax when its embedded in the TABLE function? Can you filter it with anything?

I have a table named Posts I would like to count and profile in Snowflake using the current Snowsight UI.
When I return the results via EXPLAIN using TABLULAR I am able to return the set with the combination of TABLE, RESULT_SCAN, and LAST_QUERY_ID functions, but any predicate or filter or column reference seems to fail.
Is there a valid way to do this in Snowflake with the TABLE function or is there another way to query the output of the EXPLAIN using TABLULAR?
-- Works
EXPLAIN using TABULAR SELECT COUNT(*) from Posts;
-- Works
SELECT t.* FROM TABLE(RESULT_SCAN(LAST_QUERY_ID())) as t;
-- Does not work
SELECT t.* FROM TABLE(RESULT_SCAN(LAST_QUERY_ID())) as t where operation = 'GlobalStats';
-- invalid identifier 'OPERATION', the column does not seem recognized.
Tried the third example and expected the predicate to apply to the function output. I don't understand why the filter works on some TABLE() results and not others.
You need to double quote the column name
where "operation"=
From the Documentation
Note that because the output column names from the DESC USER command
were generated in lowercase, the commands use delimited identifier
notation (double quotes) around the column names in the query to
ensure that the column names in the query match the column names in
the output that was scanned

Not getting all the rows in result while using wildcard pattern matching in sql query

I have a database named student which has a column named id which contains varchar type data as follows:
id
050350014831
050350015337
050350015338
050350015339
...
I have written the following SQL query to retrieve the id that begins with 05035 using wildcard pattern matching :
select id from student
where id like '05035%';
But I am getting 050350014831 in my output but not getting 050350015337, 050350015338, 050350015339 in the result. I am using SQL Server Management Studio. Is there anything wrong in the query?

Custom column in Custom SQL on BigQuery

I'm stacking on some issue on Tableau when I'm trying to run Custom query with string parameter. I'd like to query one column dynamically from certain table on BigQuery.
My SQL looks like.:
select <Parameters.column for research> as column,
count(*) as N
from table_name
where date=<Parameters.date>
group by 1
Here I'm trying to use parameter as column name.
But unfortunatlly I'm receive string column with one value of the parameter.
Is it possible to execute my request? If it's doable, so how to write the Custom SQL?

Why The Query Against HashKey returns no records

I am working on a new sql table. The table has a column [varbinary(8000)], where we are storing hash of a certain text. Now, I am trying to retrieve the same record back by using a where clause against the hashkey, but that yields zero records.
I have added a similar query here: http://sqlfiddle.com/#!18/be996/11
Try without the single quotes, like this
SELECT id, description
FROM ForgeRock
where id = 0x94EE059335E587E501CC4BF90613E0814F00A7B08BC7C648FD865A2AF6A22CC2
and you will get the expected result.

How to retrieve column values in the following format using SQL query?

I have a database with the following kind of values in two columns:
OPERATIONCONTEXT MANAGEDOBJECT
.oc.IN_HSI_service NNMi_NODE .nodei_v1_tns.OMi-DP NODEPrepaid_HSI_Service_MUMBAI
I have the requirement to write a SQL query to retieve these columns values separeted by a comma (,) in such a way that the OPERATIONCONTEXT column value is retrieved as it is but the MANAGEDOBJECT value is retrieved in a way that i get just the first two words separeted by a space.
Ex: I need to write a SQL query to retrieve the following result from the above sample DB data:
.oc.IN_HSI_service,NNMi_NODE .nodei_v1_tns.OMi-DP
I am able to get the two full column values separeted by a comma (,) with the following query:
SELECT distinct OPERATIONCONTEXT ||','|| MANAGEDOBJECT from $ALB_BASE_TABLE where OPERATIONCONTEXT is not NULL;
But, ofcourse along with the result i would like to put a restriction to check for not NULL and distinct values instead of repeated results and want to put the result in a CSV file through shell script. Any idea how to write the query?
PS: This is Oracle Database.
you can use
substr(MANGEDOBJECT, 0, INSTR(MANAGEDOBJECT, ' ', 1, 2))
Of course, it would be good to check if they are two spaces in string.
see SqlFiddle, and OracleDoc for Instr