select globalmap using tDBinput with Talend give the error: Invalid character constant - sql

I have to remove the accents from the person's name, but I cannot apply the function in Talend while it works in SQL oracle.
this query works in my tDBInput component :
"SELECT '"+((String)globalMap.get("copyOfSORTIE.NOM"))+"' as nom_nom_compl,
'"+((String)globalMap.get("copyOfSORTIE.ENTETE"))+"' entete
FROM DUAL"
However, when I want to add the convert function, it doesn't work
this query does not work :
"SELECT '"+((String)globalMap.get(CONVERT("copyOfSORTIE.NOM",'US7ASCII')))+"' as nom_nom_compl,
'"+((String)globalMap.get("copyOfSORTIE.ENTETE"))+"' entete
FROM DUAL"
In my talend :
I am getting this error
What is the syntax for it to work?
Thank you!

Two things there :
I don't know the CONVERT method, but I can see that you are applying it to the key of your globalMap variable , and not the value (as if you wanted to convert "myKey" and not "myValue" which is attached to the key). Are you sure this is what you want to achieve ? if not, the syntax should be something similar to "SELECT CONVERT('"+((String)globalMap.get("copyOfSORTIE.NOM"))+"','US7ASCII') "
A useful java method implemented in talend is TalendString.removeAccents("") that you can apply directly on your talend variable, thus not using a SQL method.

Related

Pass a variable into a SQL query in Excel Power Query

Long story short, I have a sql query pulling data from a database into a spreadsheet. I want to be able to change the Plant filter inside the query via Power Query, I have tried using a custom function and adding that into the query where the variable is set (see below)
Sql.Database("server", "database", [Query="DECLARE #FilterOnPlant AS varchar(3)#(lf)SET #FilterOnPlant = '" + filterOnPlant + "'#(lf)#(lf)SELECT
In doing this I keep getting the following error:
Expression.Error: We cannot apply operator + to types Text and Table.
Details:
Operator=+
Left=DECLARE #FilterOnPlant AS varchar(3)
SET #FilterOnPlant = '
Right=[Table]
I figure it has something to do with the '+' operator used but can't find an alternative.
I have tried using:
'&'
'+'
'and'
but they all yield the same error (with the exception of 'and' that error states that it's not being used in a logical statement which makes sense)
For further info:
The custom function to get the value I want is:
filterOnPlant = Excel.CurrentWorkbook(){[Name="Active_Plant"]}[Content]
The intention is to get the Value from a cell Named "Active_Plant"
EDIT:
after further testing I have found the issue lies with variable filterOnPlant, when I exchange that for a string value then the query works as expected. If anyone knows how I can get CELL().Value of a named range in power query would be super helpful
Solved!
In my filterOnPlant function I was missing {0}[Column1]
Original: filterOnPlant = Excel.CurrentWorkbook(){[Name="Active_Plant"]}[Content]
New (Working): filterOnPlant = Excel.CurrentWorkbook(){[Name="Active_Plant"]}[Content]{0}[Column1]

Dynamically change project used in a SQL query

I am using BigQuery, Standard SQL, and I want to dynamically change parts of the FROM clause, such as the project id. I have been looking for a solution for this the last 3 years - the problem has been that parameters cannot be used as inputs in the FROM clause. The benefit would be to create a stored procedure, where the project id can be passed in as an argument and can query the appropriate project. The projects would have the same datasets and table names - this would be our way of building a Master query for easy development and implementation. Instead of changing 15 clients' views, we can change the Stored Procedure once and it will push out the changes to all clients' views. However, I have always gotten hung up on dynamically changing the FROM clause!
For example:
DECLARE ProjectId STRING DEFAULT 'test_project';
SELECT col_1 FROM `#ProjectId.Dataset.Table`;
would always error out due to parameters not being able to be used in the FROM clause. However, I saw a related post on using dynamic SQL to overcome this obstacle. I've been looking into the EXECUTE IMMEDIATE function within BigQuery, as this is what has been cited to be a solution. From that post I attempted to implement in several ways:
Attempt #1:
DECLARE ProjectId STRING DEFAULT 'test_project';
EXECUTE IMMEDIATE CONCAT(
"SELECT * FROM ", #ProjectId, ".DataSet.`Table` " )
^ This gives an error "Query error: Undeclared query parameters at [2:19]"
Attempt #2:
EXECUTE IMMEDIATE CONCAT(
"SELECT * FROM ", #ProjectId, ".DataSet.`Table` " )
USING 'my-project' as ProjectId, 'my-dataset' as DataSet;
^ which gives the error "Query error: Undeclared query parameters at [1:19]"
Third and final attempt was to try declaring the parameter within the EXECUTE IMMEDIATE:
EXECUTE IMMEDIATE CONCAT(
"DECLARE ProjectId STRING DEFAULT 'test_project'; ",
"SELECT * FROM ", #ProjectId, ".DataSet.`Table` " )
USING 'my-project' as ProjectId, 'my-dataset' as DataSet;
^ which, you guessed it, results in the same error "Query error: Undeclared query parameters at [1:19]"
I am reaching out to see if anybody has had success with this? I see the value in the Dynamic SQL statements, and have read the documentation and some examples, but it still doesn't seem to work when trying to dynamically change the FROM clause. Any help is much appreciated, willing to try whatever is thrown out - excited to learn what can be done!
Just remove #:
DECLARE ProjectId STRING DEFAULT 'test_project';
EXECUTE IMMEDIATE CONCAT(
"SELECT * FROM ", ProjectId, ".DataSet.`Table` " )

Query in VB2010 based on indian language

I am developing a application based on native Indian language. I have to search the database column (in native language) student name in native language. Can anybody help me to solve this issue
my query builder code looks like this and shows syntax error
SELECT [ಕ್ರಮ ಸಂಖ್ಯೆ], [ವಿದ್ಯಾರ್ಥಿಯ ಹೆಸರು] AS Name, [ರಜಿಸ್ಟರ್ ಸಂಖ್ಯೆ], [ಡೈಸ್ ಸಂಖ್ಯೆ], [ವರ್ಗ], [ಕನ್ನಡ], [ಇಂಗ್ಲೀಷ], [ಹಿಂದಿ], [ಗಣಿತ], [ವಿಜ್ಞಾನ], [ಸಮಾಜ ವಿಜ್ಞಾನ], [ದೈಹಿಕ ಶಿಕ್ಷಣ], [ಒಟ್ಟು ಅಂಕಗಳು], [ಶೇಕಡಾ], [ಶ್ರೇಣಿ], [ಒಟ್ಟು ಅಂಕಗಳು ಅಕ್ಷರದಲ್ಲಿ], [ಲ,ಕ/ಕಲಾ ಶಿಕ್ಷಣ], [ಕಂಪ್ಯೂಟರ ಶಿಕ್ಷಣ], [ಫಲಿತಾಂಶ]
FROM Table11
WHERE ವಿದ್ಯಾರ್ಥಿಯ ಹೆಸರುCollate Indic_General_100_CI_AI LIKE N '%ಮ%'
I notice a couple things right off. Because the field in your where clause has a space in it... you have to put delimiters around it. Also, you don't seem to have a space between your field and the Collate keyword... that is necessary. Lastly, you can not have a space between the N and the apostrophe to specify a nvarchar string literal. So try a where clause like this:
WHERE [ವಿದ್ಯಾರ್ಥಿಯ ಹೆಸರು] Collate Indic_General_100_CI_AI LIKE N'%ಮ%'
If you are still getting an error, it could be that your field [ವಿದ್ಯಾರ್ಥಿಯ ಹೆಸರು] is not of a unicode string type. Make sure the field is defined as nvarchar, nchar,...etc.
From your comment it appears that you are querying a MS Access database. The above is for querying a SQL Server Engine. The where clause for access would look like this:
WHERE [ವಿದ್ಯಾರ್ಥಿಯ ಹೆಸರು] LIKE '*ಮ*'

Issue while checking data before loading in sql data loader

I am using the following code excerpt while loading data in Oracle DB using sql loader:
"tran_code POSITION(238:239)," +
"frm_acct POSITION(247:265) \"TO_NUMBER(:frm_acct)\" NULLIF :frm_acct='*******************'," +
"to_acct POSITION(269:287)," +
It is giving an error on NULL IF i guess the issue is clear that i want to insert null when the data contains only asterisk otherwise convert to number and insert.
thanx in advance.
You can try something like this -
"decode(:YOUR_COL,'***************',NULL,TO_NUMBER(:YOUR_COL))"
However, I suggest better option in this scenarios is the "external table".
Here's link for your reference :-
http://docs.oracle.com/cd/B19306_01/server.102/b14215/et_concepts.htm

Issues with a query on the AS/400 with LIKE clause

We are using Hibernate to connect to AS/400. We are having issues with a query on the AS/400
with the LIKE clause.
The following error is shown:
java.sql.SQLException: [SQL0131] Operands of LIKE not compatible or not valid
My query is its auto generated by Hibernate:
select tab_parame0_.C1IMCD as C1_560_, tab_parame0_.C1NINB as C2_560_,
tab_parame0_.C1JXCD as C3_560_, tab_parame0_.C1HLTX as C4_560_, tab_parame0_.C1HMTX as C5_560_,
tab_parame0_.C1HDST as C6_560_, tab_parame0_.C1NGNB as C7_560_, tab_parame0_.C1NJNB as C8_560_,
tab_parame0_.C1NFNB as C9_560_, tab_parame0_.C1NHNB as C10_560_, tab_parame0_.C1HCST as C11_560_
from RYC1REP tab_parame0_
where lower(tab_parame0_.C1HLTX) like lower(?)
order by tab_parame0_.C1IMCD asc
fetch first 10 rows only
SQL0131 indicates a type mismatch.
What datatype is tab_parame0_.C1HLTX? What datatype is your query parameter?
Please include your HQL/JPQL query source code for comparison.
You may have to set up an SQL trace to see exactly what the AS/400 is receiving.
See How do I obtain trace information from my Java program using the Toolbox?
I recommend you change LIKE LOWER(:parameter) to LIKE :parameter in your source query and use .toLowerCase() when you set the parameter and see how that works.