Why does the javascript snippet below not assign to LHS? - pentaho

This is my first attempt at using Pentaho's Spoon.
Input file: CSV as follows
last_name, first_name
, Nod
zanie, Rod
anie, Slob
, Vod
meanie, Dod
Transformation: Where last_name is empty, set it to first_name
Hence the transformation script is
if ( last_name == null ){
last_name = first_name;
}
Output file: Coalescent.xml
The trouble is that above replacement simply does not happen. Why?

you need to specify the field in the grid at the bottom and specify replace=Y if you want to replace the last_name field back into the stream.

Did you use a Modified JavaScript Value for your transformation? Try to add
return last_name

Related

Create a Python Program to get User Input

I am to write a python code to the following:
Ask the user to enter the first name and store it in the first_name variable.
Ask the user to enter the second name and store it in the last_name variable.
Print the full name.
I have tried it repeatedly but it kept on giving errors.
first_name = input("Enter your first name: Ade ")
last_name = input("Enter your last name:Olu ")
full_name = first_name + last_name
print(full_name)
And the expected outcome is:
Ade Olu

How can I stop executing code after getting a result?

I have a textbox named "Search" and code that filters a customer out by name. I also want to display the whole table if the textbox is empty but don't know how to do it.
NOTE : I am using Microsoft Access.
Here is my code :
SELECT * FROM Customers
WHERE Forms.[Form1].[Text4] = Forms.[Form1].[Text4] AND FirstName=Forms.[Form1].[Text4];
Thank you for any help.
You need validate if text is empty or filter to another rules, this can be something like this:
SELECT * FROM Customers WHERE Forms.[Form1].[Text4] IS NULL OR FirstName = Forms.[Form1].[Text4];

ActiveRecord (SQL) query multiple columns only if search string not empty

Using a PG database filled with registered voters.
Trying to set it up so I can search by first name, last name, zip or city. I want to be able to find all voters that match all of the entered params, but having trouble dealing with empty search fields.
where("zip LIKE ? OR city LIKE ? OR last_name LIKE ? OR first_name LIKE ?",
"#{params[:zip]}","#{params[:city]}","#{params[:last_name]}","#{params[:first_name]}")
Is there a better way to build it out so that it matches ALL entered parameters, but ignores empty string parameters? Right now if I enter a first and last name 'John Smith' I will get 'John Jones' and 'Jane Smith'.
This can do the trick:
attrs_name_to_search = %w( zip city last_name first_name )
fitlered_params = params.slice(*attrs_name_to_search).select { |_,v| v.present? }
sql_cond = filtered_params.map { |k,_| "#{k} LIKE :#{k}" }.join(' OR ')
YourModel.where(sql_cond, filtered_params)
But it should return all the records if no zip/city/last_name/first_name is given.

SQL query that choose all values when no input

I've write this query in an access 2007 database:
SELECT Ordini.ID, Ordini.Data, Clienti.Cognome, Clienti.Nome,
DettagliOrdine.IDProdotto,
Prodotti.Descrizione, Prodotti.Prezzo, DettagliOrdine.Quantità,
([Prezzo]*[Quantità]) AS Totale, Ordini.Note, Produttori.Nome, Ordini.Ordinato,
Ordini.Arrivato, Ordini.Ritirato
FROM Produttori
INNER JOIN (Prodotti
INNER JOIN ((Clienti INNER JOIN Ordini ON Clienti.ID = Ordini.IDCliente)
INNER JOIN DettagliOrdine ON Ordini.ID = DettagliOrdine.IDOrdine)
ON Prodotti.ID = DettagliOrdine.IDProdotto)
ON Produttori.ID = Prodotti.IDFornitore
WHERE (((Clienti.Cognome)=[Cognome: ])
AND ((Clienti.Nome)=[Nome: ])
AND (([Cognome: ]) Is Not Null))
ORDER BY Ordini.Data;
This query brings up an input box for the COGNOME and NOME field of research.
I need that if user write nothing (press ENTER) for that field research tag is . (all value of that field).
es. If user write a COGNOME but not a NOME (press ENTER when popup NOME window) research to be done on all the NOME with that "COGNOME".
How can I do this?
If I understand the question correctly, I think you want something like this ...
WHERE
(
Clienti.Cognome=[Cognome: ]
OR [Cognome: ] Is Null
)
AND
(
Clienti.Nome=[Nome: ]
OR [Nome: ] Is Null
)
When the parameter value is Null, no filtering is performed based on the corresponding field. But when the parameter value is not Null, it will be used to filter the result set so that it includes only rows with matching values.
For a query that is executed from with Access itself you can use the Nz() function along with the LIKE operator. For example, the query
PARAMETERS [LastName: ] TEXT(255);
SELECT ID, LastName, FirstName
FROM Clients
WHERE LastName LIKE Nz([LastName: ],"*")
will return all records* if enter nothing at the LastName: prompt, but will return only the records with the specified [LastName] if I type something in at the prompt.
*Actually, all records for which a LastName exists (i.e., IS NOT NULL). Thanks to HansUp for the correction.

concatening rows in a rails style

Suppose I want to check if some string appears as name-surname in the concatenation of two rows name and surname of a table. How do I write valid this sql in a rails style ? And is these syntaxes correct ?
SELECT (name + '-'+ surname) FROM table1 where (name + '-'+ surname = string)
table.select(:name+'-'+:surname).where((:name+'-'+:surname) == string)
I am not sure if I am understanding your question correctly, but I think this is what you are wanting. For the following string variable,
string = "John - Doe"
you want to pull a record like this from the User table
id | name | sur_name
1 | John | Doe
If this is what you want, you can actually massage your string variable like this
parsed_string = string.split('-')
name = parsed_string[0].strip # strip to remove white spaces
sur_name = parse_string[1].strip
Then, you can run the following code to get what you want:
users = User.where(:name => name, :surname => sur_name)
Hope this answers your question.