How can I use multiple inner joins with the select statement in Progress ODBC SQL? I did lot of search and could not find anything.
The below SQL works, but only with 2 tables. I want to add 3 tables and don't know how to join.
SELECT so_mstr.so_nbr AS so_Number FROM PUB.so_mstr
INNER JOIN PUB.sod_det ON so_mstr.so_nbr = sod_det.sod_nbr
AND so_mstr.so_domain = sod_det.sod_domain
Found it. Maybe someone will find it useful.
SELECT `so_mstr`.`so_nbr` as `SO_Number`
FROM (`PUB`.`so_mstr` INNER JOIN `PUB`.`sod_det` on `so_mstr`.`so_nbr` = `sod_det`.`sod_nbr`
AND `so_mstr`.`so_domain` = `sod_det`.`sod_domain`)
INNER JOIN
`PUB`.`wo_mstr` ON (`so_mstr`.`so_nbr` = `wo_mstr`.`wo_so_job` AND `so_mstr`.`so_domain` = `wo_mstr`.`wo_domain`)
Related
I have a query that works perfectly in SSMS. But when running the query in R using the DBI package, I receive several multipart identifier errors: The multi-part identifier: "rt.secondary_id" could not be bound, "rt.third_id" could not be bound, and "t2.important" could not be bound.
select t1.[main_id]
,rt.secondary_id
,rt.third_id
,t1.[date_col]
,t2.important
from t1
inner join rt on t1.main_id = rt.main_id
inner join t2 on rt.main_id = t2.main_id
inner join (select t1.main_id, max(t1.date_col) as upload_time from t1 group by t1.main_id) AS ag ON t1.main_id = ag.main_id AND t1.date_col = ag.upload_time
The unique identifier in t1 is the combination of main_id and date_col, and this query finds the most recent entry in t1 for a given main_id.
Not exactly sure if my query is structured in a poor way or this is an R issue. I've tried adding SET NOCOUNT ON to the query based on what I thought might be related issues elsewhere on stackoverflow, but no dice.
I found out what my issue was- silly (but time consuming) mistake on my part... but essentially, I was bringing my SQL query into R via paste(scan(...), collapse = " "). I had a comment in my SQL query, --, which could not be read correctly by R. Deleting the comment OR switching the comment to /* ... */ syntax fixes the problem.
I want add a new Datasets to my rdlc report in VS 2015, so I created a new data source with my stored procedure. There it is :
CREATE PROCEDURE [dbo].[getAccidents]
(#p_anneeDebut date, #p_anneeFin date)
AS
SELECT *
FROM T_ACCIDENT
LEFT OUTER JOIN TJ_ACC_PAR ON TJ_ACC_PAR.ACC_id = T_ACCIDENT.ACC_id AND TJ_ACC_PAR.ACC_type = T_ACCIDENT.ACC_type AND TJ_ACC_PAR.ACC_annee = T_ACCIDENT.ACC_annee
LEFT OUTER JOIN TR_PARTIE_CORPS ON TJ_ACC_PAR.PAR_id = TR_PARTIE_CORPS.PAR_id
LEFT OUTER JOIN TR_BLESSURE ON TJ_ACC_PAR.BLE_id = TR_BLESSURE.BLE_id
LEFT OUTER JOIN ERP.dbo.TR_COST_CENTER ON TR_COST_CENTER.COS_id = T_ACCIDENT.ACC_lieuPrecis
WHERE ACC_date <= #p_anneeFin AND ACC_date >= #p_anneeDebut
But when I add this new data source, it does not appears in the list "Data Source" so I can't select it for my report. ( The data source is well created ).
I tested with other stored procedure and it works, the problem is this line (because without this line it works too) :
LEFT OUTER JOIN ERP.dbo.TR_COST_CENTER ON TR_COST_CENTER.COS_id = T_ACCIDENT.ACC_lieuPrecis
Because this line call an other database but the query works in SQL SERVER.
How can I solve my problem ?
Have you tried running you stored proc from the Sql server, maybe its the Collation between the two databases which is different, that is if the join is on a string value. If you are calling a stored proc in SSRS the best trouble shoot is to first get the results in SSMS and if an error comes up you can easily troubleshoot. Plus try using alias on your Joins.
I have this update statement
UPDATE
pr
SET
pr.ult_prezzo_euro = ROUND(pr.ult_prezzo/fs.cambio,7)
FROM --error SQL COMMAND NOT PROPERLY ENDED
fin_prodotto prod INNER JOIN
fin_prodotto_linea fpl ON prod.prodotto_id=fpl.prodotto_id INNER JOIN
fin_att_fin faf ON fpl.attivita_fin_id=faf.attivita_fin_id INNER JOIN
fin_prezzo pr ON pr.attivita_fin_id=faf.attivita_fin_id INNER JOIN
flx_sec_posizione_dt_upd fs ON pr.attivita_fin_id=fs.attivita_fin_id
where
prod.prodotto_id=43
and faf.codice_titolo_cad_s is not null
and pr.ult_prezzo = pr.ult_prezzo_euro
and faf.divisa_quot_t<>'242'
and prod.gstd_esist_b='S'
and fpl.gstd_esist_b='S'
and faf.gstd_esist_b='S'
and pr.gstd_esist_b='S'
and pr.gstd_ult_user_s in ('AGGIORNAMENTO_POSIZIONE')
and pr.ult_prezzo>0
and fs.cambio>0;
it give me "SQL COMMAND NOT PROPERLY ENDED" pointing at FROM row,
And also i would optimize this update statement because this should run on about 2 millions records, how is possible?
i can't be sure it will be right answer without seeing your database structure, but first:
you have wrong syntax, it should look like this:
UPDATE fin_prezzo as pr SET pr.ult_prezzo_euro = ...
and then you will have to change chain of JOINS, to adequately join from fin_prezzo table (as the first table mentioned).
if it would be problem, you can 'UPDATE' another table in the statement (without changing/adding/removing updated columns)
Ad optimization part:
it will be good to start with SELECT statement (instead of UPDATE) to see, how it is joinning (maybe duplicating rows because of joins) and reduce the duplications, or not necessary joins.
secondly is quicker to move 'rules' from WHERE statement to JOIN statement
for example:
INNER JOIN fin_att_fin as faf ON fpl.attivita_fin_id=faf.attivita_fin_id AND faf.gstd_esist_b='S'
another good technique is comparing numbers instead of strings ('S', '242'...), it is simply quicker
rest is up to trying..
hope i helped a bit ;)
The target field is pk_2013_1qrt and its type is integer. But when i run the query below, results includes pk_2013_1qrt=1 values too.
Where did i go wrong?
Regards
SELECT *,ims_2012_modifiye.id AS imsID, ims_2012_modifiye.ilac_id AS ilacID,
ims_2012_modifiye.ilac_adi_duzgun AS iaDuzgun
FROM ims_2012_modifiye
LEFT JOIN ilaclar ON ims_2012_modifiye.ilac_id=ilaclar.id
WHERE ims_2012_modifiye.ilac_id NOTNULL
AND ims_2012_modifiye.asil_listede_mi=1
AND ims_2012_modifiye.ilac_id NOT IN
(SELECT ilac_id FROM piyasa_kontrol
WHERE pk_yil IN (2012,2011,2010,1900,1901))
OR
ims_2012_modifiye.oncelik_verilsin_mi=1
AND ims_2012_modifiye.pk_2013_1qrt=0
LIMIT 5
OR has lesser priority than AND. What you want is unclear, but the latest AND ims_2012_modifiye.pk_2013_1qrt=0 is applied only to the rows with ims_2012_modifiye.oncelik_verilsin_mi=1. Maybe this:
SELECT *,ims_2012_modifiye.id AS imsID, ims_2012_modifiye.ilac_id AS ilacID,
ims_2012_modifiye.ilac_adi_duzgun AS iaDuzgun
FROM ims_2012_modifiye
LEFT JOIN ilaclar ON ims_2012_modifiye.ilac_id=ilaclar.id
WHERE (ims_2012_modifiye.ilac_id NOTNULL
AND ims_2012_modifiye.asil_listede_mi=1
AND ims_2012_modifiye.ilac_id NOT IN
(SELECT ilac_id FROM piyasa_kontrol
WHERE pk_yil IN (2012,2011,2010,1900,1901))
OR
ims_2012_modifiye.oncelik_verilsin_mi=1)
AND ims_2012_modifiye.pk_2013_1qrt=0
LIMIT 5
Problem solved. As #Anton said AND has prior accessibility to query results. Move AND ims_2012_modifiye.pk_2013_1qrt=0 part just after to WHERE solves my problem. Thank you Anton, Regards
Is there any way to get the requirement coverage matrix from a specific domain/project/requirements/id ?
As I read from the REST API Help you can only get the number of covering items [test] but not the ids oh those test.
It seems that you can get access to the coverage only from ALM 11.50 so if you have something below that you may be out of luck. See the REST requirement-coverages service. But even then it's under documented for now.
Use query to get the details
SELECT REQ.RQ_REQ_ID, REQ.RQ_REQ_NAME, REQ_TYPE.TPR_NAME, REQ_COVER.RC_ENTITY_TYPE,
REQ_COVER.RC_ENTITY_ID, TEST.TS_NAME, TEST.TS_TYPE,
RUN.RN_RUN_ID, RUN.RN_RUN_NAME, RUN.RN_STATUS,
RUN.RN_TESTER_NAME, CYCLE.CY_CYCLE
FROM REQ Left join REQ_TYPE on REQ_TYPE.TPR_TYPE_ID = REQ.RQ_TYPE_ID
Left join REQ_COVER on REQ_COVER.RC_REQ_ID = REQ.RQ_REQ_ID
Left join TEST on TEST.TS_TEST_ID = REQ_COVER.RC_ENTITY_ID
Left Join RUN on RUN.RN_TEST_ID = TEST.TS_TEST_ID
Left Join CYCLE on CYCLE.CY_CYCLE_ID = RUN.RN_CYCLE_ID
where RC_ENTITY_TYPE = 'TEST'
order by REQ.RQ_REQ_ID;