Convert std::string into varchar/varchar array for sql statement - c++

I am executing a proc C(.pc) file in my project, with below steps:
Step-1:
I have a string with ',' separated delimiter:
string string1={"Delhi","Bombay","Pune");
Step-2:
I am creating a varchar
varchar str[100]
Step-3:
copy string1 to str using strcpy/strncpy
Step-4
Executing the query
select column1, column2 from table where column1 in (str.arr);
The query is returning 0 values, but if I hard code as below:
select column1, column2 from table where column1 in ('Delhi','Bombay','Pune');
I am getting 5 rows as output
I am missing how to effictively convert the string to varchar/multiset, which can be used in the select statemnt.
Are there any steps for converting the string into varchar or multiset.

Related

How to create a macro variable from a list of date in a table SAS

I have a work table named WORK.WEEK_YEAR_FESTIVITA with two records with dates 08dec2022 and 09dec2022 in the field "HolidayDate" and I would to convert this list in a macro variable like "Elenco_Date = '08dec2022'd,'09dec2022'd" and so on for other possible dates in the table WORK.WEEK_YEAR_FESTIVITA. I tried with this proc SQL:
proc sql noprint;
select distinct HolidayDate into : Elenco_Date separated by "'d,"
from WORK.WEEK_YEAR_FESTIVITA;
quit;
%put &Elenco_Date;
but the result IS:
ELENCO_DATE = 08DEC2022'd,09DEC2022;
and not
ELENCO_DATE = '08DEC2022'd,'09DEC2022'd;
as desired
Do you have suggestions?
Thanks
Create the date literal strings in the column list part of the SELECT statement.
select distinct quote(put(HolidayDate,date9.))||'d'
into :Elenco_Date separated by ','
from WORK.WEEK_YEAR_FESTIVITA
;
Or you could just store the raw number of days into the macro variable.
select distinct HolidayDate format=6.
into :Elenco_Date separated by ','
from WORK.WEEK_YEAR_FESTIVITA
;
Since there is no difference between using
where date = "08DEC2022"d
and
where date = 22987

How to copy data from one table into another table which has a record repeated column in GCP Bigquery

I am trying to copy data from one nested table into another nested table without flattening the data.
input_table : column1 STRING NULLABLE
column2 RECORD REPEATED
{
sub1 STRING NULLABLE
}
copy_table : column1 STRING NULLABLE
column2 RECORD REPEATED
{
sub STRING REPEATED
}
IF u see the sub1 column defination has been modified, in this case how do I copy the exact data without thr use of unnest. because If I use unnest the rows increase as it flatten the record by row.
query :
insert into copy_table()
select column1,
[struct(array[column2.sub])]
from input_table,
unnest(column2) as column2;
Based on your question, input_table and copy_table would be like below
CREATE TEMP TABLE input_table AS
SELECT '111' column1, [STRUCT('aaa' AS sub1), STRUCT('bbb'), STRUCT('ccc')] AS column2;
CREATE TEMP TABLE copy_table (
column1 STRING,
column2 ARRAY<STRUCT<sub ARRAY<STRING>>>
);
Instead of UNNESTing in FROM clause, you can transform column2 at SELECT list clause using a subquery and insert it into your copy_table.
INSERT INTO copy_table
SELECT column1, ARRAY(SELECT AS STRUCT [sub1] AS sub FROM UNNEST(column2)) AS column2
FROM input_table;

UFT API TEST: Create SQL query based on values from previous step activity at run time

Steps to be performed in UFT API Test:
Get JSON RESPONSE from added REST activity in test flow
Add Open DB connection activity
Add Select Data activity with query string
SELECT Count(*) From Table1 Where COL1 = 'XXXX' and COL2 = ' 1234'
(here COL2 value has length of 7 characters including spaces)
In the above query values in where clause is received(dynamically at run time) from JSON response.
When i try to link the query value using link to data source with custom expression
eg:
SELECT COUNT(*) FROM Table1 Where COL1 =
'{Step.ResponseBody.RESTACTIVITYxx.OBJECT[1].COL1}' and COL2 =
'{Step.ResponseBody.RESTACTIVITYxx.OBJECT[1].COL2}'
then the QUERY changed (excluding spaces in COL2) to:
SELECT Count(*) From Table1 Where COL1 = 'XXXX' and COL2 = '1234'
I eventried with concatenate and Replace string activity but same happens.
Please kindly help..
You can use the StringConcatenation action, to build de Query String.
Use the String as Query in Database "Select data"

Cassandra only returning a subset of my rows when using varchar

I have encountered a problem when using Apache Cassandra, in that I have 500k rows of entries in a 4 column table. 3 of the columns make up the compound key and the last one is a help column for indexing so that I can search in between the other ones using greater than or lesser than operators. The 3 components of the compund key are integers, and the help column is a varchar filled with help for all 500k entries. Now, when i use:
select count(*) from table where help='help' limit 1kk allow filtering;
I should have gotten as result 500k, but I get 36738.
Any ideas as to why this is happening?
If the table has for columns: id, column1, column2, help; my query needs to be something similar to:
select * from table where column1 > 15 and column1 < 1000 and column2 > 200 and column2 < 10000 and help='help' limit 1kk allow filtering;
Also when I created the table, I used PRIMARY KEY(id, column1, column2)

Mysql match all word either from column1 or column2

For example: In MySql I have column1 and column2.
How to make sql query that will return all records that contain all search words in either column 1 or column 2.
So far I was using:
Select * from table1 where (column1 like '%search from input box%' or column2 like '%search from input box%')
If your table is MyISAM:
SELECT *
FROM table1
WHERE MATCH(column1) AGAINST ('+search +from +input +box' IN BOOLEAN MODE)
UNION
SELECT *
FROM table2
WHERE MATCH(column2) AGAINST ('+search +from +input +box' IN BOOLEAN MODE)
Create a FULLTEXT INDEX on column1 and column2 (independently) for this to work fast, and adjust #ft_min_word_len to match words as short as you need.
If it's not MyISAM:
SELECT *
FROM table
WHERE (
column1 RLIKE '[[:<:]]search[[:>:]]'
AND column1 RLIKE '[[:<:]]from[[:>:]]'
AND column1 RLIKE '[[:<:]]input [[:>:]]'
AND column1 RLIKE '[[:<:]]box[[:>:]]'
)
OR
(
column2 RLIKE '[[:<:]]search[[:>:]]'
AND column2 RLIKE '[[:<:]]from[[:>:]]'
AND column2 RLIKE '[[:<:]]input [[:>:]]'
AND column2 RLIKE '[[:<:]]box[[:>:]]'
)