This is in symfony.
How to do it better this work on one env on other doesn't don't know why
r. is Recruitment Entity which has onetomany relation to RecruitmentUsers
$this->createQueryBuilder('r')
->select('r')
->addSelect('(SELECT SUM(b.payedAmount) FROM APP\Entity\RecruitmentUsers b WHERE b.isActive = 1 and r.id = b.recruitment) as payedSum')
->addSelect('(SELECT SUM(c.declaredAmount) FROM APP\Entity\RecruitmentUsers c WHERE c.isActive = 1 and r.id = c.recruitment) as declaredSum')
->leftJoin('r.recruitmentUsers','u')
->groupBy('r.id')
->orderBy('r.id', 'DESC')
->getQuery()
->getResult()
In dev env everything works fine in prod i got this error:
Fatal error: Uncaught Doctrine\ORM\Query\QueryException: SELECT r, (SELECT SUM(b.payedAmount) FROM APP\Entity\RecruitmentUsers b WHERE b.isActive = 1 and r.id = b.recruitment) as payedSum, (SELECT SUM(c.declaredAmount) FROM APP\Entity\RecruitmentUsers c WHERE c.isActive = 1 and r.id = c.recruitment) as declaredSum FROM App\Entity\Recruitment r LEFT JOIN r.recruitmentUsers u GROUP BY r.id ORDER BY r.id DESC in /usr/home/eliteinvestments/domains/4eliteinvestments.pl/vendor/doctrine/orm/lib/Doctrine/ORM/Query/QueryException.php:43 Stack trace: #0 /usr/home/eliteinvestments/domains/4eliteinvestments.pl/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(487): Doctrine\ORM\Query\QueryException::dqlError('SELECT r, (SELE...') #1 /usr/home/eliteinvestments/domains/4eliteinvestments.pl/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(987): Doctrine\ORM\Query\Parser->semanticalError('line 0, col 42 ...', Array) #2 /usr/home/eliteinvestments/domains/4eliteinvestments.pl/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(1 in /usr/home/eliteinvestments/domains/4eliteinvestments.pl/templates/bundles/TwigBundle/Exception/error.html.twig on line 6
I done cache:clear, cache:warmup, doctrine:cache:clear-query, doctrine:cache:clear-result, doctrine:cache:clear-metadata
none of it works.
Any hints ?
I would try something like this. Not entirely sure what you want tho.
$this->createQueryBuilder('r')
->select('r.id, SUM(u.payedAmount), SUM(u.declaredAmount)')
->leftJoin('r.recruitmentUsers','u')
->where('u.isActive = 1')
->groupBy('r.id')
->orderBy('r.id', 'DESC')
->getQuery()
->getResult();
Related
In the below query when i comment one line AND EVT.EVT_EVNT_ID(+) = DPT.DPT_EVNT_ID or add outer join (+) in one line AND EVT.EVT_ENTITY_ID ='G' the query will fetch results, else it will not give any results.
`
select * from
(select B11.ext_db_id,B11.FRST_LINE_OF_PRFRD_NAME, E11.*, D1.D1_evnt_id,
(SELECT E1.E1_DT
FROM S1core.E1_EVNT_DT_DTLS E1
WHERE E1.E1_ENTITY_ID = D1.D1_ENTITY_ID
AND E1.E1_EVNT_ID = D1.D1_EVNT_ID
AND E1.E1_D1_ID = D1.D1_D1_ID
AND E1.E1_DT_TYP = 'MEET'
AND E1.E1_OPTN_SEQ_N = '999'
AND E1.STATUS = 'AUTHD' ) "MEET_DATE"
FROM S1core.E1_EVNT_DT_DTLS E11, S1core.SECURITY_ACCOUNT SFA,
S1core.EXTRNL_SYS_DETAILS EXT,
S1core.D1_DPOT_EVNT_DTLS D1, S1core.IP_ACNT_RELATION i1,
S1core.ELG_ELGBLTY E1,S1core.P1_D1_PRXY_DTLS P1, S1core.EVT_DTLS EVT,
S1core.BUSINESS_PARTNER B1, S1core.BUSINESS_PARTNER B11
WHERE
P1.P1_EVNT_ID(+) = D1.D1_EVNT_ID
AND B1.BP_ID = i1.IP_ID
AND SFA.BP_ID = B11.BP_ID
AND B11.OWNER_ENTITY = SFA.OWNER_ENTITY
AND P1.P1_D1_ID(+) = D1.D1_D1_ID
AND P1.P1_ENTITY_ID(+) = D1.D1_ENTITY_ID
AND P1.STATUS(+) = 'AUTHD'
AND EXT.LVL_REF = SFA.SCA_REF
AND EXT.OWNER_ENTITY = SFA.owner_entity
AND EXT.EXTRNL_SYS_ID = '39'
AND EXT.BP_ID = SFA.BP_ID
AND EXT.LVL = 5
AND E1.ELG_SEC_ID = D1.D1_SEC_ID
AND D1.D1_ENTITY_ID = E1.ELG_ENTITY_ID
AND D1.D1_EVNT_ID = E1.ELG_EVNT_ID
AND D1.D1_D1_ID = E1.ELG_D1_ID
AND E1.ELG_ENTITY_ID = SFA.OWNER_ENTITY
AND E1.ELG_ACNT_ID = SFA.SCA_REF
AND i1.owner_entity = SFA.OWNER_ENTITY
AND i1.owner_entity = B1.OWNER_ENTITY
AND i1.SCA_REF = SFA.SCA_REF
AND i1.stat <> 2
AND EVT.EVT_ENTITY_ID ='G'
AND EVT.EVT_EVNT_ID(+) = D1.D1_EVNT_ID
AND EVT.STATUS(+) = 'AUTHD'
AND E11.E1_ENTITY_ID = D1.D1_ENTITY_ID
AND E11.E1_EVNT_ID = D1.D1_EVNT_ID
AND E11.E1_D1_ID = D1.D1_D1_ID
AND D1.D1_EVNT_GRP = 'MEETING'
AND E1.ELG_FNL_ELGBL_QNTTY > 0
AND D1.D1_ENTITY_ID = 'GSSIN' -- P_D1_ENTITY_ID
AND B11.ext_db_id LIKE 'LICMF' -- P_GLOBAL_CUSTODIAN
AND B1.ext_db_id LIKE '%' -- P_FUND_MANAGER
AND SUBSTR(EXT.LEVEL_EXTNL_SYS,1,5) LIKE '%' -- P_SUB_ACCOUNT_ID
AND SUBSTR(EXT.LEVEL_EXTNL_SYS,6,9) LIKE '%' -- P_SCHEMA_ID
AND SUBSTR( D1.D1_EVNT_TYP, 1, 4 ) LIKE '%' -- P_EVENT_TYPE
AND E11.E1_DT_TYP = 'MEET'
and D1.D1_evnt_id='12457886544'
AND D1.OU_ID IN('17','80') -- ('S1 INDIA PC')
) ;
Am I missing any outer join or the query is having any other issue as i can see that dpt_evnt_id='12457886544'is available in all tables.
`
I tried to run this query by commenting AND EVT.EVT_EVNT_ID(+) = DPT.DPT_EVNT_ID
and by adding outer join in EVT.EVT_ENTITY_ID (+) ='G'
You have:
AND EVT.EVT_ENTITY_ID ='G'
AND EVT.EVT_EVNT_ID(+) = D1.D1_EVNT_ID
AND EVT.STATUS(+) = 'AUTHD'
Even though the second two have (+) the first one does not so the join to EVT will be treated as an INNER JOIN and not an OUTER JOIN.
You should convert your code to use ANSI joins as it will be much easier to spot issues like this.
Note: There may be more issues like this. However, your code has so many joins, the syntax is archaic, and we have no way of validating the correctness that I stopped looking after finding the first issue. You are going to need to debug it all to check for any other issues.
I have used left to join multiple tables in my controller method. It returns data as desired but when I type into search box '0' it throws an error.
Using https://datatables.yajrabox.com/ this Laravel Datatable plugin
It only happen when single zero(0) is there in search box. '00' or 't0102' works fine.
only single '0' as search value throws an error.
Happens on the demo site to
https://datatables.yajrabox.com/eloquent/row-num
try to search for 0(zero) only and it will throw back you an error.
After spending couple of hours I came to the conclusion the it is because in MySql query LIKE %0% is not adding inverted commas('') around 0(zero)
It should be LIKE '%0%' instead LIKE %0%.
Code snippet of problem
Below is my Query Builder Code
$surveys = DB::table('surveys as su')
->leftJoin('assignments as a', 'su.assignment_id', '=', 'a.id')
->leftJoin('rounds as r', 'a.round_id', '=', 'r.id')
->leftJoin('projects as p', 'r.project_id', '=', 'p.id')
->leftJoin('sites as s', 'a.site_id', '=', 's.id')
->leftJoin('fieldreps as f', 'a.fieldrep_id', '=', 'f.id')
->leftJoin('chains as ch','p.chain_id','=','ch.id')
->leftJoin('clients as c','ch.client_id','=','c.id')
->leftJoin('surveys_templates as t', 'su.template_id', '=', 't.id')
->where(function ($query) {
$query->where('a.is_reported', '=', true)
->orWhere('a.is_partial', '=', true)
->orWhere('a.is_approved', '=', true);
})
//->where('su.service_code', '!=', '')
->select([
'a.id as assignment_id',
'a.fieldrep_id',
'a.deadline_date',
'a.is_reported',
'a.is_partial',
'a.is_approved',
'c.client_logo',
'p.id as project_id',
'p.project_name',
'r.id as round_id',
'r.round_name',
's.site_code',
's.site_name',
's.city',
's.state',
's.zipcode',
'su.id as survey_id',
'su.status',
'su.service_code',
't.template_name',
DB::raw("CONCAT(IFNULL( DATE_FORMAT(a.schedule_date,'%e/%c/%Y'), DATE_FORMAT(r.schedule_date,'%e/%c/%Y')), ' ' , IFNULL(a.start_time, r.start_time)) as assignment_scheduled"),
DB::raw("CONCAT(IFNULL( DATE_FORMAT(a.schedule_date,'%d %b %Y'), DATE_FORMAT(r.schedule_date,'%d %b %Y')), ' ' , IFNULL(a.start_time, r.start_time)) as assignment_scheduled_date"),
DB::raw("CONCAT(DATE_FORMAT(a.start_date,'%d %b %Y'),' ',a.start_time) as assignment_starts"),
DB::raw('CONCAT(f.first_name," ",f.last_name) as schedule_to'),
]);
Syntax error or access violation: 1583 Incorrect parameters in the call to native function 'LOWER' (SQL: select count(*) as aggregate from (select a.id as assignment_id, a.fieldrep_id, a.deadline_date, a.is_reported, a.is_partial, a.is_approved, c.client_logo, p.id as project_id, p.project_name, r.id as round_id, r.round_name, s.site_code, s.site_name, s.city, s.state, s.zipcode, su.id as survey_id, su.status, su.service_code, t.template_name, CONCAT(IFNULL( DATE_FORMAT(a.schedule_date,'%e/%c/%Y'), DATE_FORMAT(r.schedule_date,'%e/%c/%Y')), ' ' , IFNULL(a.start_time, r.start_time)) as assignment_scheduled, CONCAT(IFNULL( DATE_FORMAT(a.schedule_date,'%d %b %Y'), DATE_FORMAT(r.schedule_date,'%d %b %Y')), ' ' , IFNULL(a.start_time, r.start_time)) as assignment_scheduled_date, CONCAT(DATE_FORMAT(a.start_date,'%d %b %Y'),' ',a.start_time) as assignment_starts, CONCAT(f.first_name," ",f.last_name) as schedule_to from surveys as su left join assignments as a on su.assignment_id = a.id left join rounds as r on a.round_id = r.id left join projects as p on r.project_id = p.id left join sites as s on a.site_id = s.id left join fieldreps as f on a.fieldrep_id = f.id left join chains as ch on p.chain_id = ch.id left join clients as c on ch.client_id = c.id left join surveys_templates as t on su.template_id = t.id where (a.is_reported = 1 or a.is_partial = 1 or a.is_approved = 1) and (LOWER(s.site_code) LIKE %0% or LOWER(su.service_code) LIKE %0% or LOWER(p.project_name) LIKE %0% or LOWER(r.round_name) LIKE %0% or LOWER(s.city) LIKE %0% or LOWER(surveys as su.assignment_scheduled) LIKE %0% or LOWER(t.template_name) LIKE %0% or LOWER(surveys as su.schedule_to) LIKE %0%) order by lpad(s.site_code, 10, 0) desc) count_row_table)'
I am trying to get data out of my db but i am getting the above mentioned error on this line. Please HELP!!!!
join specvalue in db.Types on devicespecifications.DeviceTypeFKID equals devicetypes.DeviceTypeID
I have Tried switching the equals but it doesn't work. Please Help
List<DeviceDetails> devicedetails = (
from devices in db.Device
join devicespecifications in db.DeviceSpecifications on devices.DeviceID equals devicespecifications.DeviceFKID
join devicetypes in db.Types on devices.DeviceTypeFKID equals devicetypes.DeviceTypeID
join specvalue in db.Types on devicespecifications.DeviceTypeFKID equals devicetypes.DeviceTypeID // This Line is giving me the above mentioned error
join devicehistories in db.DeviceHistory on devices.DeviceID equals devicehistories.DeviceFKID
join locations in db.Locations on devices.LocationFKID equals locations.LocationID
join ips in db.IP on devices.DeviceID equals ips.DeviceFKID
where devices.DeviceID == id
select new DeviceDetails()
{
DeviceID = devices.DeviceID,
DeviceName = devices.DeviceName,
EntryDate = devices.EntryDate,
AssignDate = devices.AssignDate,
DeviceStatus = devices.DeviceStatus.ToString(),
MACAddress = devices.MACAddress,
DateRepaired= devicehistories.DateRepaired,
Remarks= devicehistories.Remarks,
SpecificationType = devicespecifications.DeviceTypeFKID,
devicetypes.DeviceTypeID,
SpecificationValue = devicespecifications.SpecificationValue,
FamilyIP = ips.FamilyIP,
ChildIP = ips.ChildIP,
LocationTypeValue = locations.LocationTypeValue,
DeviceTypeValue = devicetypes.DeviceTypeValue
}).ToList<DeviceDetails>();
return devicedetails;
}
In the mentioned row:
join specvalue in db.Types on devicespecifications.DeviceTypeFKID equals devicetypes.DeviceTypeID
you use devicetypes name again but you should use specvalue in this line.
I wrote the query (below) in PL/SQL Developer for a client and would like to import it into Oracle Discoverer Desktop 11g so the report is self-serve. The query works perfectly in PL/SQL but when I go to import it into Discoverer, I get the following errors: "Error: Syntax error: token JOIN at position 760. Error: Parse stopped due to fatal errors."
Can anyone tell me what these errors mean and how to resolve the issue?
Thanks!
Query:
Select eid.person_code, eid.last_name plnownr_lname, eid.first_name plnownr_fname, eid.birth_date plnownr_DOB, des.status_code, dun.unit_code, ect.last_name BenRecip_LNAME, ect.first_name BenRecip_fname, ect.birth_date BenRecip_DOB,decode(ect.relation,'00','Unknown','01','Spouse','02','Common-Law Spouse','03','Partner', '05','Daughter','06','Son','07','Step-Daughter','08','Step-Son','09', 'Granddaughter','11', 'Father','12','Mother', '20','Sister','21','Brother','24','Aunt','28','Nephew','29','Ex-spouse','31','Friend','43','Trust','50','User Defined','52','User Defined', '53','User Defined','54','User Defined',ect.relation) relation, bpn.description, bpn.plan_code, bend.premium_start_date, bend.premium_end_date
From p2k_hr_identities eid
Join p2k_hr_contacts ect on ect.eid_id = eid.id
Join p2k_be_benefit_recipients bbr on bbr.ect_id = ect.id
Join p2k_be_enrollments ben on ben.id = bbr.ben_id
Join p2k_be_plan_definitions bpn on bpn.id = ben.bpn_id
Join p2k_hr_employments eem on eem.eid_id = eid.id
and eem.termination_date is null
Join p2k_hr_assignments eas on eas.eem_id = eem.id
Join p2k_hr_assignment_details easd on easd.eas_id = eas.id
and easd.expiry = to_date('3999-12-31', 'yyyy-mm-dd')
Join p2k_cm_units dun on dun.id = easd.dun_id
Join p2k_be_enrollment_details bend on bend.ben_id = ben.id
and bend.premium_end_date = to_date('3999-12-31','yyyy-mm-dd')
and bend.premium_start_date != to_date('0001-01-01','yyyy-mm-dd')
Join p2k_cm_employment_statuses des on des.id = easd.des_id
and des.status_code not in ('TERMINATED', 'RETIRED')
Union
Select eid.person_code, eid.last_name plnownr_lname, eid.first_name eplnownr_fname, eid.birth_date plnownr_dob, des.status_code, dun.unit_code, eid.last_name BenRecip_lname, eid.first_name BenRecip_fname, eid.birth_date BenRecip_dob, 'Employee-NoRelation', bpn.description, bpn.plan_code, bend.premium_start_date, bend.premium_end_date
From p2k_hr_identities eid
Join p2k_hr_employments eem on eem.eid_id = eid.id
and eem.termination_date is null
Join p2k_be_enrollments ben on ben.eem_id = eem.id
Join p2k_be_plan_definitions bpn on bpn.id = ben.bpn_id
Join p2k_hr_assignments eas on eas.eem_id = eem.id
Join p2k_hr_assignment_details easd on easd.eas_id = eas.id
and easd.expiry = to_date('3999-12-31', 'yyyy-mm-dd')
Join p2k_cm_units dun on dun.id = easd.dun_id
Join p2k_be_enrollment_details bend on bend.ben_id = ben.id
and bend.premium_end_date = to_date('3999-12-31','yyyy-mm-dd')
and bend.premium_start_date != to_date('0001-01-01','yyyy-mm-dd')
Join p2k_cm_employment_statuses des on des.id = easd.des_id
and des.status_code not in ('TERMINATED', 'RETIRED')
Order by 2,3,5,6
This linq to ef syntax produces the sql syntax shown below. How can I get it to produce without the CROSS JOIN? The cross join is giving me a ton of extra records.
vehicleList = (from _vehicle in shireyContext.Vehicles
join _statusDescription in shireyContext.StatusDescriptions
on _vehicle.Status equals _statusDescription.StatusId
join _newOptions2 in shireyContext.VehicleOption_New
on _vehicle.StockNo equals _newOptions2.StockNo
where _vehicle.NewOrUsed == NewOrUsed && _vehicle.Model == Model && _newOptions2.Color != null
from _newOptions in shireyContext.VehicleOption_New
select new VehicleDomainEntity
{
StockNo = _vehicle.StockNo,
Year = _vehicle.VehicleYear,
Make = _vehicle.Make,
Model = _vehicle.Model,
Description = _newOptions2.Description,
ExteriorColor = _vehicle.ExteriorColor,
InteriorColor = _vehicle.InteriorColor,
InternetPrice = _vehicle.CodedCost,
ListPrice = _vehicle.ListPrice,
Status = _statusDescription.StatusDescriptionText,
NewOrUsed = _vehicle.NewOrUsed,
Mileage = _vehicle.Mileage,
VIN = _vehicle.VIN
}).ToList();
produces this sql:
SELECT
Extent2.StatusId AS StatusId,
Extent1.StockNo AS StockNo,
Extent1.VehicleYear AS VehicleYear,
Extent1.Make AS Make,
Extent1.Model AS Model,
Extent3.Description AS Description,
Extent1.ExteriorColor AS ExteriorColor,
Extent1.InteriorColor AS InteriorColor,
Extent1.CodedCost AS CodedCost,
Extent1.ListPrice AS ListPrice,
Extent2.StatusDescriptionText AS StatusDescriptionText,
Extent1.NewOrUsed AS NewOrUsed,
Extent1.Mileage AS Mileage,
Extent1.VIN AS VIN
FROM dbo.Vehicles AS Extent1
INNER JOIN dbo.StatusDescription AS Extent2 ON Extent1.Status = Extent2.StatusId
INNER JOIN dbo.VehicleOption_New AS Extent3 ON Extent1.StockNo = Extent3.StockNo
CROSS JOIN dbo.VehicleOption_New AS Extent4
WHERE (Extent1.NewOrUsed = 'N') AND (Extent1.Model = 'cts' AND (Extent3.Color IS NOT NULL))
I think you want this
from _vehicle in shireyContext.Vehicles
join _statusDescription in shireyContext.StatusDescriptions
on _vehicle.Status equals _statusDescription.StatusId
join _newOptions2 in shireyContext.VehicleOption_New into VehicleNew
on _vehicle.StockNo equals _newOptions2.StockNo
where _vehicle.NewOrUsed == NewOrUsed && _vehicle.Model == Model && _newOptions2.Color != null
from _newOptions in VehicleNew
The two lines that are changed are:
join _newOptions2 in shireyContext.VehicleOption_New into VehicleNew
and
from _newOptions in VehicleNew