SQL INNER JOIN syntax Error BigQuery // New to SQL - sql

I'm getting this error "No matching signature for operator = for argument types: INT64, STRING. Supported signature: ANY = ANY at [9:6]
" while trying to JOIN two table in BQ, Login ID column is listed in the two tables but BQ shows that there's an error on line 9enter image description here
SELECT
performance.name,
performance.ahtdn,
tnps.tnps,
FROM
`data-exploration-2023.jan_scorecard_2023.performance-jan-2023` AS performance
LEFT JOIN
`data-exploration-2023.jan_scorecard_2023.tnps-jan-2023` AS tnps
ON performance.login_id = tnps.login_id
I've checked the syntax for INNER JOIN online and on BQ documentation but I couldn't find the reason why I get this error.

The error should be due to trying to join INT64 and STRING column. It should be resolved casting the numeric column to text one like this:
CAST(performance.login_id AS STRING) = tnps.login_id
or cast the second one if it is the numeric.

Related

Select columns from a table with a space in its name

I'm trying to select columns from two tables, Lignes and Détail Production. Détail Production links to the first one with the key NoLigne (which is the same name in both tables).
I know that I have to put [ ] or `` around the table's name, but I'm having the error No value given for one or more required parameters, which I believe means that SQL doesn't recognize the name. I tried aliasing the name of the table having a space in its name, but I have the same error. Here is my code:
SELECT
NoProduction,
Quantite,
DateMaxProd,
Lignes.Référence
FROM
[Détail Production] AS D
INNER JOIN
Lignes ON D.NoLigne = Lignes.NoLigne
WHERE
D.Soldee = 0 AND
D.EtatLigne = 0 AND
Lignes.Soldee = 0 AND
(QteRecue - Quantite - Acompter * NbHS)>0
Unfortunately, I can't get rid of the alias or the name of the table in the FROM and WHERE clause because my tables share columns with the same name. I can't rename the tables or the columns, and I'm actually using the software Windev which uses HFSQL as a dbms. I'm trying to connect to an access database with the OLEDB connector, and when I switch to HFSQL it works.
Here is a mre:
SELECT
*
FROM
[Détail Production]
INNER JOIN
Lignes ON [Détail Production].NoLigne = Lignes.NoLigne
When using HFSQL database, it works, when using OLEDB with an access database, it throws the error No value given for one or more required parameter
Thanks for your help.
I found the problem:
SELECT
D.NoProduction,
D.Quantite,
D.DateMaxProd,
Lignes.Référence
FROM
[Détail Production] AS D
INNER JOIN
Lignes ON D.NoLigne = Lignes.NoLigne
WHERE
D.Soldee = 0 AND
D.EtatLigne = 0 AND
Lignes.Soldee = 0 AND
(D.QteRecue - D.Quantite - D.Acompter * D.NbHS) > 0
I was missing the comparison on the last condition of the WHERE clause. I thought it was because of the alias or the brackets because others online had similar problems and the error changed as I tried other ways of writing the FROM clause. The right way to write a name with spaces in HFSQL is with brackets [ ]. Also, there were problems with names not matching accents from the database.

Cannot run the query as it says "unable to execute query, invalid operation or syntax using multi-valued field" in Access

SELECT
tbl_facilityinformation.exportid,
qry_numberofpatientsgreaterthan12withdepressionscreen.numberofuniquepatientsagegreaterthan12withdepressionscreening AS NumberUniquePatientsWithDepressionScreening,
qry_numberofuniquepersonsgreaterthan12years.numberofuniquepersonsgreaterthan12years,
[qry_numberofpatientsgreaterthan12withdepressionscreen]![numberofuniquepatientsagegreaterthan12withdepressionscreening] /
[qry_numberofuniquepersonsgreaterthan12years]![numberofuniquepersonsgreaterthan12years] AS PercentageOfPatientsGreaterThan12WithDepressionScreen
FROM
(
tbl_facilityinformation INNER JOIN qry_numberofpatientsgreaterthan12withdepressionscreen ON
tbl_facilityinformation.exportid = qry_numberofpatientsgreaterthan12withdepressionscreen.exportid
)
INNER JOIN qry_numberofuniquepersonsgreaterthan12years ON
tbl_facilityinformation.exportid = qry_numberofuniquepersonsgreaterthan12years.exportid
GROUP BY
tbl_facilityinformation.exportid,
qry_numberofpatientsgreaterthan12withdepressionscreen.numberofuniquepatientsagegreaterthan12withdepressionscreening,
qry_numberofuniquepersonsgreaterthan12years.numberofuniquepersonsgreaterthan12years;
I dont understand why I'm getting the error:
Unable to execute query, invalid operation or syntax using multi-valued field.
I have tried to look for syntax errors but could not find any.

How to Join (equal) two data columns that belongs to the String and Double types respectively in Alibaba MaxCompute?

I am not authorized to share the table details.
For instance, let me consider an Example:
I am trying to join two columns of String and Double data types respectively in Alibaba MaxCompute.
In the earlier version of MaxCompute, the String and Double data types are converted to the bigint data type at the cost of precision. 1.1 = “1” in a Join condition.
Whereas the same code does not work in the new version of the MaxCompute. The code syntax is like follows:
SELECT * FROM t1 JOIN t2 ON t1.double_value = t2.string_value;
Error:
WARNING:[1,48] implicit conversion from STRING to DOUBLE, potential data loss, use CAST function to suppress
What is the correct syntax to do the join operation in Alibaba MaxCompute V2?
I did a bit of digging and it seems like this SQL command is the recommended way of getting around this issue.
select * from t1 join t2 on t.double_value = cast(t2.string_value as double);
As the error message suggests:
SELECT *
FROM t1 JOIN
t2
ON CAST(t1.double_value as string) = t2.string_value;

Upper to Lowercase conversion in SQL Server

I have the below columns in from 2 different tables -
DimTeamProject.ProjectNodeGUID DimIteration.ProjectGUID
------------------------------ ------------------------
FAE8B08E-286E-487D-B1C1-011853028CDB fae8b08e-286e-487d-b1c1-011853028cdb
I was trying a join operation while matching the case. It gave me an error like
Conversion failed when converting from a character string to uniqueidentifier.
The query I was trying was -
select
p.ProjectNodeName, i.IterationName
from
DimTeamProject p, DimIteration i
where
(p.ProjectNodeGUID) = UPPER(i.ProjectGUID)
I tried the "char" and "cast" function too but without success. Please help.
DimIteration.ProjectGUID is an "nvarchar" & DimTeamProject.ProjectNodeGUID is an "uniqueidentifer"
Just cast the appropriate side as a uniqueidentifier:
select p.ProjectNodeName, i.IterationName
from DimTeamProject p
inner join DimIteration i on p.ProjectNodeGUID =
CAST(i.ProjectGUID as uniqueidentifier)
See the demo with a SQL Fiddle.

Firebird - How to use "(? is null)" for selecting blank parameters

I am working with an Excel Report linked to a Firebird 2.0 DB and I have various parameters linked to cell references that correspond to drop down lists.
If a parameter is left blank, I want to select all the possible options. I am trying to accomplish this by putting ... WHERE... (? is null), as described in http://www.firebirdsql.org/refdocs/langrefupd25-sqlnull.html , but I get an "Invalid Data Type" error.
I found some Firebird documentation (http://www.firebirdfaq.org/faq92/) where it talks about this error, but it states that "The solution is to cast the value to appropriate datatype, so that all queries return the same datatype for each column." and I'm not quite sure what that means in my situation.
SELECT C.COSTS_ID,
C.AREA_ID,
S.SUB_NUMBER,
S.SUB_NAME,
TP.PHASE_CODE,
TP.PHASE_DESC,
TI.ITEM_NUMBER,
TI.ITEM_DESC,
TI.ORDER_UNIT,
C.UNIT_COST,
TI.TLPE_ITEMS_ID
FROM TLPE_ITEMS TI
INNER JOIN TLPE_PHASES TP ON TI.TLPE_PHASES_ID = TP.TLPE_PHASES_ID
LEFT OUTER JOIN COSTS C ON C.TLPE_ITEMS_ID = TI.TLPE_ITEMS_ID
LEFT OUTER JOIN AREA A ON C.AREA_ID = A.AREA_ID
LEFT OUTER JOIN SUPPLIER S ON C.SUB_NUMBER = S.SUB_NUMBER
WHERE ((C.AREA_ID = 1 OR C.AREA_ID = ?) OR **(? IS NULL))**
AND ((S.SUB_NUMBER = ?) OR **(? IS NULL))**
AND ((TI.ITEM_NUMBER = ?) OR **(? IS NULL))**
AND ((TP.PHASE_CODE STARTING WITH ?) OR **(? IS NULL))**
ORDER BY TP.PHASE_CODE
Any help is greatly appreciated.
If you are not using Firebird 2.5 (but version 2.0 or higher), or if you are using a driver that doesn't support the SQL_NULL datatype introduced in Firebird 2.5, then you need to use an explicit CAST, eg;
SELECT *
FROM TLPE_ITEMS TI
WHERE TI.ITEM_NUMBER = ? OR CAST(? AS INTEGER) IS NULL
This will identify the second parameter as an INTEGER to the driver (and to Firebird), allowing you to set it to NULL.
Now the faq you reference mentions cast the value to appropriate datatype, what they mean is that you should not cast to a data type that might result to conversion errors if it isn't null.
In my example I cast to INTEGER, but if the values are actually strings and you use say "IX0109302" as a value, you will get a conversion error as it isn't an appropriate INTEGER. To prevent that, you would need to cast to a (VAR)CHAR of sufficient length (otherwise you get a truncation error).
If you are using Firebird 1.5 or earlier this trick will not work, see CORE-778, in that case you might get away with something like TI.ITEM_NUMBER = ? OR 'T' = ?, where you set the second parameter to either 'T' (true) or 'F' (false) to signal whether you want everything or not; this means that you need to move the NULL detection to your calling code.