This question already has answers here:
Oracle "(+)" Operator
(4 answers)
Closed 9 years ago.
We tried to migrate from Oracle to Postgres. We use ora2pg , but we have an error with this code:
SELECT DISTINCT UPU.USUA_C_USUARIO
FROM GN_USUARIOS U,TR_USUARIOS_X_PERFILES_USUARIO UPU,TR_V_PERFILES_USUARIOS PU
WHERE (U.C_USUARIO = UPU.USUA_C_USUARIO(+))
AND (UPU.PEUS_X_PEUS = PU.X_PEUS)
AND U.C_USUARIO = USU.C_USUARIO))
OR NOT EXISTS (
SELECT UPU2.USUA_C_USUARIO
FROM TR_USUARIOS_X_PERFILES_USUARIO UPU2
WHERE UPU2.USUA_C_USUARIO = USU.C_USUARIO)
OR USER = (
SELECT V_CONSTANTE
FROM GN_CONSTANTES
WHERE C_CONSTANTE = 'TRUSUPROP')
We have an error with PU.USUA_C_USUARIO(+). We dont have enough experience in this kind of conversions. How can we transform the code with LEFT OUTER JOIN ?
Thanks!
Probably like so:
FROM GN_USUARIOS U
LEFT JOIN TR_USUARIOS_X_PERFILES_USUARIO UPU ON U.C_USUARIO = UPU.USUA_C_USUARIO
LEFT JOIN TR_V_PERFILES_USUARIOS PU ON UPU.PEUS_X_PEUS = PU.X_PEUS
WHERE U.C_USUARIO = USU.C_USUARIO)
Or possibly:
FROM GN_USUARIOS U
LEFT JOIN ( SELECT UPU.USUA_C_USUARIO, ...
FROM TTR_USUARIOS_X_PERFILES_USUARIO UPU
JOIN TR_V_PERFILES_USUARIOS PU ON UPU.PEUS_X_PEUS = PU.X_PEUS
) UPU_PU ON U.C_USUARIO = UPU_PU.USUA_C_USUARIO
WHERE U.C_USUARIO = USU.C_USUARIO)
In either case, be wary that there's a USU table that is defined nowhere and mismatched parenthesis in your query.
Related
This question already has answers here:
Oracle "(+)" Operator
(4 answers)
Closed 1 year ago.
I have this Oracle code, which I need to convert to SQL Server:
FROM
dbo.userid t,
dbo.securityuser us,
dbo.dbaudit dba
WHERE
t.userid = us.userid
t.userid = dba.keyvalue(+)
I have a problem with
t.userid = dba.keyvalue(+)
Here the plus operator is after the column and the left joins are done using
table1.col(+) = table2.col
Please help me to understand what actually it is doing.
I think you want:
FROM dbo.userid t JOIN
dbo.securityuser us
ON t.userid = us.userid LEFT JOIN
dbo.dbaudit dba
ON t.userid = dba.keyvalue
I have the following SQL Syntax:
SELECT firmenstamm.firmen_id,
firmenstamm.firmenname_1,
kreditorenstamm.kreditorenname_1,
debitor.debitoren_id,
debitor.deb_id_vom_kreditor,
debitorenstamm.debitorenname_1,
zahlung.zahlung_nr,
zahlung.zahlung_betrag,
zahlung.zahlung_betrag_offen,
zahlung.zahlung_datum,
kreditorenstamm.kreditoren_id,
bankbewegung.name_ag,
bankbewegung.verwendungzweck
FROM debitor,
debitorenstamm,
firmenstamm,
kreditorenstamm,
zahlung
LEFT JOIN z_bankbewegung ON zahlung.zahlungs_id = z_bankbewegung.zahlungs_id,
LEFT JOIN bankbewegung ON z_bankbewegung.babe_id = bankbewegung.babe_id
WHERE ( firmenstamm.firmen_id = kreditorenstamm.firmen_id ) and
( kreditorenstamm.kreditoren_id = debitor.kreditoren_id ) and
( debitor.debitoren_id = debitorenstamm.debitoren_id ) and
( debitor.kreditoren_id = zahlung.kreditoren_id ) and
( debitor.deb_id_vom_kreditor = zahlung.deb_id_vom_kreditor ) and
( ( zahlung.zahlung_betrag_offen > 0 ) )
My Problem now is the following:
As you can see I made a multiple left join on the same table. I always get the error message "Table or view does not exist" (ORA-00942).
zahlung
LEFT JOIN z_bankbewegung ON zahlung.zahlungs_id = z_bankbewegung.zahlungs_id,
LEFT JOIN bankbewegung ON z_bankbewegung.babe_id = bankbewegung.babe_id
I can't see my mistake. Does anyone have any idea?
You are mixing the old, ancient and fragile implicit joins (listing all tables separated by a comma in the FROM clause, then put the join conditions in to the WHERE clause) and the "modern"1) explicit JOIN operator. Don't do that. Use explicit JOINs for everything:
SELECT ...
FROM debitor
JOIN debitorenstamm ON debitor.debitoren_id = debitorenstamm.debitoren_id
JOIN kreditorenstamm ON kreditorenstamm.kreditoren_id = debitor.kreditoren_id
JOIN firmenstamm ON firmenstamm.firmen_id = kreditorenstamm.firmen_id
JOIN zahlung
ON debitor.kreditoren_id = zahlung.kreditoren_id
AND debitor.deb_id_vom_kreditor = zahlung.deb_id_vom_kreditor
LEFT JOIN z_bankbewegung ON zahlung.zahlungs_id = z_bankbewegung.zahlungs_id
LEFT JOIN bankbewegung ON z_bankbewegung.babe_id = bankbewegung.babe_id
WHERE zahlung.zahlung_betrag_offen > 0
1) "modern" is relative: explicit JOINs have been introduced in the SQL standard in 1992 more than 25 years ago. So that's hardly "modern" in the sense of "brand new".
This question already has answers here:
Update a table using JOIN in SQL Server?
(13 answers)
Closed 6 years ago.
I have a simple select statement that identifies the rows I want to update. Basically i want to copy the vad_description to the vb_description and can't quite figure this out. Any Help would be appreciated.
SELECT
variant_bom.vb_id
,variant_bom.vb_description
,variant_detail.vad_description
FROM dbo.variant_bom
INNER JOIN dbo.variant_detail
ON variant_bom.vb_vad_id = variant_detail.vad_id
INNER JOIN dbo.variant_setting
ON variant_setting.vas_vad_id = variant_detail.vad_id
WHERE variant_setting.vas_manufactured_variant = 1
AND variant_setting.vas_discontinued_product = 0
Try something like this
UPDATE vb
SET vb.vb_description = vd.vad_description
FROM dbo.variant_bom vb
INNER JOIN dbo.variant_detail vd
ON vb.vb_vad_id = vd.vad_id
INNER JOIN dbo.variant_setting vs
ON vs.vas_vad_id = vd.vad_id
WHERE vs.vas_manufactured_variant = 1
AND vs.vas_discontinued_product = 0
Giving Alias name to tables will make your query more readable
This question already has answers here:
How do I create a table based on another table [duplicate]
(2 answers)
Closed 6 years ago.
everyone! I would like to save the table after I used INNER JOIN.
CREATE TABLE result AS (
SELECT measures.Day,
SELECT measures.Day,
stations.Name,
measures.name_measure,
measures_of_stations.Count,
measures.unit
FROM
measures_of_stations
INNER JOIN
stations
ON measures_of_stations.id_station = stations.id_station
INNER JOIN
measures
ON measures_of_stations.id_measure = measures.id_measure)
But I have an error "Invalid syntax next to ( ". Why?
Thank you in advance :)
You need to use the INTO clause, see example below:
SELECT measures.Day,
stations.Name,
measures.name_measure,
measures_of_stations.Count,
measures.unit INTO result
FROM
measures_of_stations
INNER JOIN
stations
ON measures_of_stations.id_station = stations.id_station
INNER JOIN
measures
ON measures_of_stations.id_measure = measures.id_measure
SELECT measures.Day,
stations.Name,
measures.name_measure,
measures_of_stations.Count,
measures.unit
INTO result
FROM
measures_of_stations
INNER JOIN
stations
ON measures_of_stations.id_station = stations.id_station
INNER JOIN
measures
ON measures_of_stations.id_measure = measures.id_measure
This question already has answers here:
SQL: JOIN syntax error
(2 answers)
Closed 9 years ago.
I am attempting to eliminate unwanted duplicate query results. The gist is that the field [CUSIP] exists in all tables in question, however, the field [4DTYR] exists in all tables except [IDX_FS].
I had previously only joined the tables via the [CUSIP] field, and that resulted in the query produced unwanted duplicate results (some sort of a permutation of [4DTYR] from all the tables that contained that field).
Then, I made the modification below. However, now I'm receiving a JOIN syntax error. Can anyone kindly help? I've reposted just in case this Q got a little bit stale. Thanks!
FROM
(((IDX_FS LEFT JOIN DATA_BS
ON IDX_FS.CUSIP = DATA_BS.CUSIP)
LEFT JOIN DATA_Footnotes
ON IDX_FS.CUSIP = DATA_Footnotes.CUSIP)
LEFT JOIN DATA_IS
ON IDX_FS.CUSIP = DATA_IS.CUSIP)
LEFT JOIN DATA_SP
ON IDX_FS.CUSIP = DATA_SP.CUSIP
AND (((DATA_BS LEFT JOIN DATA_IS
ON DATA_BS.CUSIP = DATA_IS.CUSIP
AND DATA_BS.4DTYR = DATA_IS.4DTYR)
LEFT JOIN DATA_SP
ON DATA_BS.CUSIP = DATA_SP.CUSIP
AND DATA_BS.4DTYR = DATA_SP.4DTYR)
LEFT JOIN DATA_Footnotes.4DTYR
ON DATA_BS.CUSIP = DATA_Footnotes.CUSIP
AND DATA_BS.4DTYR = DATA_Footnotes.4DTYR
Looks like your error is here
LEFT JOIN DATA_Footnotes.4DTYR -- this is not a valid table name
ON DATA_BS.CUSIP = DATA_Footnotes.CUSIP
AND DATA_BS.4DTYR = DATA_Footnotes.4DTYR
removing the .4DTYR should fix your error
LEFT JOIN DATA_Footnotes
ON DATA_BS.CUSIP = DATA_Footnotes.CUSIP
AND DATA_BS.4DTYR = DATA_Footnotes.4DTYR