Missing content of field CreatorFullName and ModifierFullName in GeneralJournalEntryLines - exact-online

The business object GeneralJournalEntryLines contains the GL transaction lines of Exact Online. For performance tuning reasons, we are changing our scripts that copy data from Exact Online to our on-premise database to only include changes where possible instead of a full copy.
However, a query on GeneralJournalEntries joined with GeneralJournalEntryLines sometimes returns a null value in CreatorFullName and ModifiedFullName.
I've tried to reproduce new rows with this problem but those work fine.
Is this a database corruption? Or a join fault on my side?
The Exact Online query is:
use <DIVISION CODE>
select GE.Created GE_Created
,GE.Division GE_Division
,GE.EntryID GE_EntryID
,GE.EntryNumber GE_EntryNumber
,GE.FinancialPeriod GE_FinancialPeriod
,GE.FinancialYear GE_FinancialYear
,GE.JournalCode GE_JournalCode
,GE.Modified GE_Modified
,GE.Reversal GE_Reversal
,GE.Status GE_Status
,GE.Type GE_Type
,GL.AccountCode GL_AccountCode
,GL.AmountDC GL_AmountDC
,GL.AmountVATDC GL_AmountVATDC
,GL.AssetCode GL_AssetCode
,GL.CostCenter GL_CostCenter
,GL.CostUnit GL_CostUnit
,GL.CreatorFullName GL_CreatorFullName
,GL.Date GL_Date
,GL.Description GL_Description
,GL.GLAccountCode GL_GLAccountCode
,GL.LineNumber GL_LineNumber
,GL.ModifierFullName GL_ModifierFullName
,GL.OurRef GL_OurRef
,GL.ProjectCode GL_ProjectCode
,GL.Quantity GL_Quantity
,GL.VATBaseAmountDC GL_VATBaseAmountDC
,GL.VATCode GL_VATCode
,GL.VATPercentage GL_VATPercentage
,GL.VATType GL_VATType
from ExactOnlineREST..GeneralJournalEntries GE
inner join ExactOnlineREST..GeneralJournalEntryLines GL
on GE.EntryID=GL.EntryID
where GE.Status <> 50
or ( GE.Status = 50 and ( (GE.FinancialYear*100) + GE.FinancialPeriod = 201501 and GE.Modified > '09/01/2017 14:03:09' ) )
or ( GE.Status = 50 and ( (GE.FinancialYear*100) + GE.FinancialPeriod = 201502 and GE.Modified > '09/01/2017 14:03:09' ) )
or ( GE.Status = 50 and ( (GE.FinancialYear*100) + GE.FinancialPeriod = 201503 and GE.Modified > '09/01/2017 14:03:09' ) )
or ( GE.Status = 50 and ( (GE.FinancialYear*100) + GE.FinancialPeriod = 201504 and GE.Modified > '09/01/2017 14:03:09' ) )
or ( GE.Status = 50 and ( (GE.FinancialYear*100) + GE.FinancialPeriod = 201505 and GE.Modified > '09/01/2017 14:03:08' ) )
or ( GE.Status = 50 and ( (GE.FinancialYear*100) + GE.FinancialPeriod = 201506 and GE.Modified > '09/01/2017 14:03:08' ) )
or ( GE.Status = 50 and ( (GE.FinancialYear*100) + GE.FinancialPeriod = 201507 and GE.Modified > '09/01/2017 14:27:27' ) )
or ( GE.Status = 50 and ( (GE.FinancialYear*100) + GE.FinancialPeriod = 201508 and GE.Modified > '09/01/2017 14:27:27' ) )
or ( GE.Status = 50 and ( (GE.FinancialYear*100) + GE.FinancialPeriod = 201509 and GE.Modified > '09/01/2017 14:27:27' ) )
or ( GE.Status = 50 and ( (GE.FinancialYear*100) + GE.FinancialPeriod = 201510 and GE.Modified > '09/01/2017 14:27:26' ) )
or ( GE.Status = 50 and ( (GE.FinancialYear*100) + GE.FinancialPeriod = 201511 and GE.Modified > '09/01/2017 14:27:27' ) )
or ( GE.Status = 50 and ( (GE.FinancialYear*100) + GE.FinancialPeriod = 201512 and GE.Modified > '09/01/2017 14:27:26' ) )
local export results as "D:\Invantive\data\uit_EOL\40570GeneralJournals.csv" format csv
local exit

When using the query:
select *
from ExactOnlineREST..GeneralJournalEntryLines GL
where gl.modifierfullname is null or gl.creatorfullname is null
it seems that all rows where the modifiedfullname or creatorfullname is missing have an associated user GUID from a short list. It are also (based on creation date) all records which are of considerable age.
It seems that Exact Online APIs internally make a left outer join with the users table, for which no longer active users return no information.

Related

Snowflake Function input is datetime, but when i call the function it's not quite working

with temp AS (
SELECT CAST(SUM(sreg.ScrapQuantity) AS INT) AS Quantity,
sreas.Name AS ScrapReason,
to_date((DATEADD(MINUTE, 30 * (DATE_PART(MINUTE, sreg.ScrapTime) / 30), DATEADD(HOUR, TIMESTAMPDIFF(HOUR, '0', sreg.ScrapTime), '0')))) AS DATETIME,
sreg.EquipmentID AS EquipmentID
FROM ScrapRegistration sreg
INNER JOIN ScrapReason sreas ON sreas.ID = sreg.ScrapReasonID
INNER JOIN WorkRequest wr ON wr.ID = sreg.WorkRequestID
INNER JOIN SegmentRequirementEquipmentRequirement srer ON srer.SegmentRequirementID = wr.SegmentRequirementID
GROUP BY DATEADD(MINUTE, 30 * (DATE_PART(MINUTE, sreg.ScrapTime) / 30), DATEADD(HOUR, TIMESTAMPDIFF(HOUR, '0', sreg.ScrapTime), '0')),
sreg.EquipmentID,
sreas.Name
)
select temp.EquipmentID
from RAW_CPMS_AAR.equipment e, temp
Where e.ID = (select * from table(cfn_GetShiftIDFromDateTime_test(temp.DateTime::DATETIME, 0))) --this works with datetime
when i run this query above, i get Processing aborted due to error 300010:391167117; incident 3245754.. I believe this is an issue with the temp.datetime -- when i run the same codebut hardcoding the function input, i get the desired output.
with temp AS (
SELECT CAST(SUM(sreg.ScrapQuantity) AS INT) AS Quantity,
sreas.Name AS ScrapReason,
to_date((DATEADD(MINUTE, 30 * (DATE_PART(MINUTE, sreg.ScrapTime) / 30), DATEADD(HOUR, TIMESTAMPDIFF(HOUR, '0', sreg.ScrapTime), '0')))) AS DATETIME,
sreg.EquipmentID AS EquipmentID
FROM ScrapRegistration sreg
INNER JOIN ScrapReason sreas ON sreas.ID = sreg.ScrapReasonID
INNER JOIN WorkRequest wr ON wr.ID = sreg.WorkRequestID
INNER JOIN SegmentRequirementEquipmentRequirement srer ON srer.SegmentRequirementID = wr.SegmentRequirementID
GROUP BY DATEADD(MINUTE, 30 * (DATE_PART(MINUTE, sreg.ScrapTime) / 30), DATEADD(HOUR, TIMESTAMPDIFF(HOUR, '0', sreg.ScrapTime), '0')),
sreg.EquipmentID,
sreas.Name
)
select temp.EquipmentID
from RAW_CPMS_AAR.equipment e, temp
Where e.ID = (select * from table(cfn_GetShiftIDFromDateTime_test('2021-12-02 10:03:0.00'::datetime, 0))) --this works with datetime
it seems that that somwehere along the line, it's not liking the date format i put in. it's not returning me an error of not liking the input.
here is the function.
CREATE OR REPLACE FUNCTION DB_BI_DEV.RAW_CPMS_AAR.cfn_GetShiftIDFromDateTime (dateTime TIMESTAMP_NTZ(9), shiftCalendarID int)
RETURNS table (shiftID int)
AS
$$
WITH T0 (ShiftCalendarID, CurDay, PrvDay)
AS (
SELECT TOP 1
ID AS ShiftCalendarID,
DATEDIFF( day, BeginDate, dateTime ) % PeriodInDays + 1 AS CurDay,
( CurDay + PeriodInDays - 2 ) % PeriodInDays + 1 AS PrvDay
FROM RAW_CPMS_AAR.ShiftCalendar
WHERE ID = shiftCalendarID
OR ( shiftCalendarID IS NULL
AND Name = 'Factory'
AND BeginDate <= dateTime )
ORDER BY BeginDate DESC
),
T1 (TimeValue)
AS (
SELECT TIME_FROM_PARTS(
EXTRACT(HOUR FROM dateTime),
EXTRACT(MINUTE FROM dateTime),
EXTRACT(SECOND FROM dateTime))
)
SELECT ID as shiftID
FROM RAW_CPMS_AAR.Shift, T0, T1
WHERE Shift.ShiftCalendarID = T0.ShiftCalendarID
AND ( ( FromDay = T0.CurDay AND FromTimeOfDay <= T1.TimeValue AND TillTimeOfDay > T1.TimeValue )
OR ( FromDay = T0.CurDay AND FromTimeOfDay >= TillTimeOfDay AND FromTimeOfDay <= T1.TimeValue )
OR ( FromDay = T0.PrvDay AND FromTimeOfDay >= TillTimeOfDay AND TillTimeOfDay > T1.TimeValue )
)
$$
;

Syntax error with Complex MySQL Procedure/Function

I have come up with a fairly complex query that computes and returns two date fields based on some input arguments. These date values need to be further used in a report which will have lots of other fields. As you can see there are 4 input variables and 2 output variables.
set #caSplit = 0.3;
set #flSplit = 0.7;
set #formulaForAvgUsed='useAvgOfAll';
set #itemNumber = 'TAB_120_IVR_POLY';
select
max(case when compCA >0 then rollingDate else current_date end) as oosDateForCA,
max(case when compFL >0 then rollingDate else current_date END) as oosDateForFL
from
(
select
items.item, items.rollingDate, perDaySalesCA, perDaySalesFL,
items.total_items_in_ca, total_items_in_fl, flAsnItems.flASNQty, caAsnItems.caASNQty,
#prevDayCA := case
when cntr = 0 then total_items_in_ca
when greatest(#prevDayCA,0) + coalesce(caASNQty,0) = 0 then 0
else greatest(#prevDayCA,0) - perDaySalesCA - IF(#prevDayFL > perDaySalesFL, 0, perDaySalesFL) + coalesce(caASNQty,0)
end as compCA,
#prevDayCA as caInv,
#prevDayFL := case
when cntr = 0 then total_items_in_fl
when greatest(#prevDayFL,0) + coalesce(flASNQty,0) = 0 then 0
else greatest(#prevDayFL,0) - perDaySalesFL - IF(#prevDayCA > perDaySalesCA, 0, perDaySalesCA) + coalesce(flAsnQty, 0)
end as compFL,
#prevDayFL as flInv
from
(select #prevDayCA := -1, #prevDayFL := -1)vars,
(
select
item, total_items_in_fl, total_items_in_ca,
ROUND(avgToUse * #caSplit / 30) as perDaySalesCA,
ROUND(avgToUse * #flSplit / 30) as perDaySalesFL,
#cntr as cntr,
DATE_ADD(current_date, INTERVAL #cntr DAY) as rollingDate,
#cntr := #cntr + 1
from
(
select
#cntr := 0
) vars
join counter c
join
(
select
i.number as item, i.total_items_in_ca, i.total_items_in_fl,
case when #formulaForAvgUsed = 'useNewMSA' then
i.new_msa
when #formulaForAvgUsed = 'useMSA' then
i.monthly_sales_average
when #formulaForAvgUsed = 'useWMSA' then
i.weighted_monthly_sales_average
when #formulaForAvgUsed = 'useTwoWeeks' then
i.two_wks_average * 2
when #formulaForAvgUsed = 'useMaxAvg' then
greatest(i.new_msa, i.monthly_sales_average, i.weighted_monthly_sales_average, i.two_wks_average *2)
when #formulaForAvgUsed = 'useAvgOfAll' then
case when DATE_ADD(i.first_sold_date, INTERVAL 365 DAY) > CURRENT_DATE then
(i.new_msa + i.two_wks_average *2 + i.monthly_sales_average)/3
else
(i.new_msa + i.two_wks_average *2 + i.monthly_sales_average+ i.weighted_monthly_sales_average)/4
end
when #formulaForAvgUsed = 'useAvgMSAAndNewMSA' then
(i.new_msa + i.monthly_sales_average)/2
when #formulaForAvgUsed = 'useAvgWMSAAndTwoWeeks' then
case when DATE_ADD(i.first_sold_date, INTERVAL 365 DAY) < CURRENT_DATE then
i.weighted_monthly_sales_average
else
( i.two_wks_average *2 + i.weighted_monthly_sales_average)/2
end
else
greatest(i.new_msa, i.monthly_sales_average, i.weighted_monthly_sales_average, i.two_wks_average *2)
end as avgToUse
from
item i
where
i.number = #itemNumber
) T
) items
left join
(
select
i.number, date(estimated_arrival_date) as asnDate,
sum((aol.loaded_quantity - aol.received_Quantity) * p.quantity) as caASNQty
from
item i join asn_order_line aol on aol.item_id = i.item_id
join asn_order ao on ao.asn_order_id = aol.asn_order_id
join pack p on aol.pack_id = p.pack_id
where
aol.line_status = 'New' and ao.status in ('New' , 'Partial Receipt', 'Receiving', 'Partially Received')
and facility = 'WHSE'
and i.number = #itemNumber
group by
i.number, date(estimated_arrival_date)
) caAsnItems on caAsnItems.number = items.item and caAsnItems.asnDate = rollingDate
left join
(
select
i.number,
date(estimated_arrival_date) as asnDate,
sum((aol.loaded_quantity - aol.received_Quantity) * p.quantity) as flASNQty
from
item i join asn_order_line aol on aol.item_id = i.item_id
join asn_order ao on ao.asn_order_id = aol.asn_order_id
join pack p on aol.pack_id = p.pack_id
where
aol.line_status = 'New' and ao.status in ('New' , 'Partial Receipt', 'Receiving', 'Partially Received')
and facility = 'FLOR'
and i.number = #itemNumber
group by
i.number, date(estimated_arrival_date)
) flAsnItems on flAsnItems.number = items.item and flAsnItems.asnDate = rollingDate
group by
rollingDate
having
caInv > 0 || flInv > 0
|| rollingDate <= greatest(max(flAsnItems.asnDate), max(caAsnItems.asnDate))
order by
rollingDate DESC
)top;
My intent is to create a procedure and select the values in the top level into the output variables. Using MySQL Workbench when I try to create with this syntax, it throws a syntax error but doesn't say what exactly is the issue.
DELIMITER //
CREATE PROCEDURE `compute_oos_date2` (IN itemNumber VARCHAR(50), IN formulaForAvgUsed VARCHAR(50), IN caSplit FLOAT, IN flSplit FLOAT, OUT oosDateForCA DATE, OUT oosDateForFL DATE)
BEGIN
SET #prevDayCA = -1;
SET #prevDayFL = -1;
select
max(case when compCA >0 then rollingDate else current_date end) into oosDateForCA,
max(case when compFL >0 then rollingDate else current_date END) into oosDateForFL
from
(
select
items.item, items.rollingDate, perDaySalesCA, perDaySalesFL,
items.total_items_in_ca, total_items_in_fl, flAsnItems.flASNQty, caAsnItems.caASNQty,
#prevDayCA := case
when cntr = 0 then total_items_in_ca
when greatest(#prevDayCA,0) + coalesce(caASNQty,0) = 0 then 0
else greatest(#prevDayCA,0) - perDaySalesCA - IF(#prevDayFL > perDaySalesFL, 0, perDaySalesFL) + coalesce(caASNQty,0)
end as compCA,
#prevDayCA as caInv,
#prevDayFL := case
when cntr = 0 then total_items_in_fl
when greatest(#prevDayFL,0) + coalesce(flASNQty,0) = 0 then 0
else greatest(#prevDayFL,0) - perDaySalesFL - IF(#prevDayCA > perDaySalesCA, 0, perDaySalesCA) + coalesce(flAsnQty, 0)
end as compFL,
#prevDayFL as flInv
from
(
select
item, total_items_in_fl, total_items_in_ca,
ROUND(avgToUse * caSplit / 30) as perDaySalesCA,
ROUND(avgToUse * flSplit / 30) as perDaySalesFL,
#cntr as cntr,
DATE_ADD(current_date, INTERVAL #cntr DAY) as rollingDate,
#cntr := #cntr + 1
from
(select #cntr := 0) vars
join counter c
join
(
select
i.number as item, i.total_items_in_ca, i.total_items_in_fl,
case when formulaForAvgUsed = 'useNewMSA' then
i.new_msa
when formulaForAvgUsed = 'useMSA' then
i.monthly_sales_average
when formulaForAvgUsed = 'useWMSA' then
i.weighted_monthly_sales_average
when formulaForAvgUsed = 'useTwoWeeks' then
i.two_wks_average * 2
when formulaForAvgUsed = 'useMaxAvg' then
greatest(i.new_msa, i.monthly_sales_average, i.weighted_monthly_sales_average, i.two_wks_average *2)
when formulaForAvgUsed = 'useAvgOfAll' then
case when DATE_ADD(i.first_sold_date, INTERVAL 365 DAY) > CURRENT_DATE then
(i.new_msa + i.two_wks_average *2 + i.monthly_sales_average)/3
else
(i.new_msa + i.two_wks_average *2 + i.monthly_sales_average+ i.weighted_monthly_sales_average)/4
end
when formulaForAvgUsed = 'useAvgMSAAndNewMSA' then
(i.new_msa + i.monthly_sales_average)/2
when formulaForAvgUsed = 'useAvgWMSAAndTwoWeeks' then
case when DATE_ADD(i.first_sold_date, INTERVAL 365 DAY) < CURRENT_DATE then
i.weighted_monthly_sales_average
else
( i.two_wks_average *2 + i.weighted_monthly_sales_average)/2
end
else
greatest(i.new_msa, i.monthly_sales_average, i.weighted_monthly_sales_average, i.two_wks_average *2)
end as avgToUse
from
item i
where
i.number = itemNumber
) T
) items
left join
(
select
i.number, date(estimated_arrival_date) as asnDate,
sum((aol.loaded_quantity - aol.received_Quantity) * p.quantity) as caASNQty
from
item i join asn_order_line aol on aol.item_id = i.item_id
join asn_order ao on ao.asn_order_id = aol.asn_order_id
join pack p on aol.pack_id = p.pack_id
where
aol.line_status = 'New' and ao.status in ('New' , 'Partial Receipt', 'Receiving', 'Partially Received')
and facility = 'WHSE'
and i.number= itemNumber
group by
i.number, date(estimated_arrival_date)
) caAsnItems on caAsnItems.number = items.item and caAsnItems.asnDate = rollingDate
left join
(
select
i.number,
date(estimated_arrival_date) as asnDate,
sum((aol.loaded_quantity - aol.received_Quantity) * p.quantity) as flASNQty
from
item i join asn_order_line aol on aol.item_id = i.item_id
join asn_order ao on ao.asn_order_id = aol.asn_order_id
join pack p on aol.pack_id = p.pack_id
where
aol.line_status = 'New' and ao.status in ('New' , 'Partial Receipt', 'Receiving', 'Partially Received')
and facility = 'FLOR'
and i.number = itemNumber
group by
i.number, date(estimated_arrival_date)
) flAsnItems on flAsnItems.number = items.item and flAsnItems.asnDate = rollingDate
group by
rollingDate
having
caInv > 0 || flInv > 0
|| rollingDate <= greatest(max(flAsnItems.asnDate), max(caAsnItems.asnDate))
order by
rollingDate DESC
)top
END //
DELIMITER;
Can anyone help ?
I figured out , the syntax to load into multiple variables is
select 'abc', 'def' into var1, var2
Earlier I was using
select 'abc' into var1, 'def' into var2

SQL Union all throws SQL Syntax error but the two SELECTS are ok

I want to join 2 SELECT statements. They both work fine individually but if I try to use the Union All I get a syntax error:
[42000][1064] You have an error in your SQL syntax; check the manual
that corresponds to your MySQL server version for the right syntax to
use near '' at line 29
Which doesn't make any sense to me. I searched for that error message but I don't use quotes in that line (29 is UNION ALL)
SELECT NULL AS id,
table_a.calendar_day AS
calendar_day,
'XXX' AS mbr_entity
,
'total' AS
product,
'total' AS
mbr_stock_category,
'total' AS component,
SUM(IF(table_a.mbr_entity = 'XXX', aim, 0)) AS aim,
SUM(IF(table_a.mbr_entity = 'XXX', cf, 0)) AS cf,
SUM(IF(table_a.mbr_entity = 'XXX', mbr, 0)) AS mbr,
SUM(IF(table_a.mbr_entity = 'XXX', ytd, 0)) AS ytd,
SUM(IF(table_a.mbr_entity = 'XXX', forecast, 0)) AS forecast,
SUM(table_b.a
+ table_b.b
+ table_b.c
+ table_b.d
+ table_b.e) AS actual
FROM table_a
left join table_b
ON table_b.calendar_day =
table_a.calendar_day
AND table_b.mbr_entity =
table_a.mbr_entity
WHERE MONTH(table_a.calendar_day) = MONTH(CURRENT_DATE())
GROUP BY calendar_day
UNION ALL
SELECT NULL AS id,
table_a.calendar_day,
table_a.mbr_entity,
'total' AS product,
'total' AS
mbr_stock_category,
'total' AS component,
SUM(IF(table_a.mbr_entity = 'XXX', 0, aim)) AS aim,
SUM(IF(table_a.mbr_entity = 'XXX', 0, cf)) AS cf,
SUM(IF(table_a.mbr_entity = 'XXX', 0, mbr)) AS mbr,
SUM(IF(table_a.mbr_entity = 'XXX', 0, ytd)) AS ytd,
SUM(IF(table_a.mbr_entity = 'XXX', 0, forecast)) AS forecast,
SUM(table_b.a
+ table_b.b
+ table_b.c
+ table_b.d
+ table_b.e) AS actual
FROM table_a
left join table_b
ON table_b.calendar_day =
table_a.calendar_day
AND table_b.mbr_entity =
table_a.mbr_entity
WHERE table_a.mbr_entity <> 'XXX'
AND MONTH(table_a.calendar_day) = MONTH(CURRENT_DATE())
GROUP BY calendar_day,
mbr_entity
Try Use Code Again
( SELECT NULL AS
id,
table_a.calendar_day AS calendar_day,
'XXX' AS mbr_entity,
'total' AS product,
'total' AS mbr_stock_category,
'total' AS component,
SUM( IF ( table_a.mbr_entity = 'XXX', aim, 0 ) ) AS aim,
SUM( IF ( table_a.mbr_entity = 'XXX', cf, 0 ) ) AS cf,
SUM( IF ( table_a.mbr_entity = 'XXX', mbr, 0 ) ) AS mbr,
SUM( IF ( table_a.mbr_entity = 'XXX', ytd, 0 ) ) AS ytd,
SUM( IF ( table_a.mbr_entity = 'XXX', forecast, 0 ) ) AS forecast,
SUM( table_b.a + table_b.b + table_b.c + table_b.d + table_b.e ) AS actual
FROM
table_a
LEFT JOIN table_b ON table_b.calendar_day = table_a.calendar_day
AND table_b.mbr_entity = table_a.mbr_entity
WHERE
MONTH ( table_a.calendar_day ) = MONTH ( CURRENT_DATE ( ) )
GROUP BY
calendar_day
)
UNION ALL
(
SELECT NULL AS
id,
table_a.calendar_day,
table_a.mbr_entity,
'total' AS product,
'total' AS mbr_stock_category,
'total' AS component,
SUM( IF ( table_a.mbr_entity = 'XXX', 0, aim ) ) AS aim,
SUM( IF ( table_a.mbr_entity = 'XXX', 0, cf ) ) AS cf,
SUM( IF ( table_a.mbr_entity = 'XXX', 0, mbr ) ) AS mbr,
SUM( IF ( table_a.mbr_entity = 'XXX', 0, ytd ) ) AS ytd,
SUM( IF ( table_a.mbr_entity = 'XXX', 0, forecast ) ) AS forecast,
SUM( table_b.a + table_b.b + table_b.c + table_b.d + table_b.e ) AS actual
FROM
table_a
LEFT JOIN table_b ON table_b.calendar_day = table_a.calendar_day
AND table_b.mbr_entity = table_a.mbr_entity
WHERE
table_a.mbr_entity <> 'XXX'
AND MONTH ( table_a.calendar_day ) = MONTH ( CURRENT_DATE ( ) )
GROUP BY
calendar_day,
mbr_entity
)

mysql matching multiple and's and or's

I am trying to get rows from a table where there are matches on multiple other tables.
This is the query I am running.
SELECT qt.*, DATEDIFF(CURRENT_DATE, STR_TO_DATE(up.DOB, '%m-%d-%Y')) / 365 AS Age
FROM UserProfile AS up, Game AS g, QuestionTable AS qt
WHERE NOT EXISTS(SELECT * FROM Options WHERE UserID = 75 AND QID = qt.QID AND DateTime >= CURDATE())
AND g.Active = 1 AND g.QID = qt.QID
AND (((g.Gender = up.Gender OR g.Gender = 'B') AND ((g.City = up.City AND g.Zip = up.Zip AND g.Country = up.Country) OR g.Home = 0) AND ((Age BETWEEN g.Maximum AND g.Minimum) OR g.Age = 0) AND ((SQRT( POW( 69.1 * ( g.Latitude - -93.5746359 ) , 2 ) + POW( 69.1 * ( 44.9737707 - g.Longitude ) * COS( g.Latitude / 57.3 ) , 2 ) ) > g.Distance) OR g.Geo = 0)) OR g.Special = 0)
GROUP BY qt.QID
I have ran this expression through C# and it returns true, yet it is only matching on the 'g.Special = 0' part through MySql.
Any help on this would be much appreciated!
Resolved the issue by fixing some mistakes I made and changed the query to this,
SELECT *
FROM QuestionTable AS qt
WHERE NOT EXISTS
(SELECT * FROM Options WHERE UserID = 75 AND QID = qt.QID AND DateTime >= CURDATE())
AND EXISTS(SELECT g.* FROM UserProfile AS up, Game AS g WHERE g.Active = 1 AND g.QID = qt.QID AND(g.Special = 0 OR(
(g.Gender = up.Gender OR g.Gender = 'B') AND
((g.City = up.City AND g.zip = up.Zip AND g.Country = up.Country) OR g.Home = 0) AND
((SQRT( POW( 69.1 * ( g.Latitude - 44.9737707 ) , 2 ) + POW( 69.1 * ( -93.5746359 - g.Longitude ) * COS( g.Latitude / 57.3 ) , 2 ) ) < g.Distance) OR g.Geo = 0) AND
((DATEDIFF(CURRENT_DATE, STR_TO_DATE(DOB, '%m/%d/%Y'))/365.25 BETWEEN g.Minimum AND g.Maximum) OR g.Age = 0))))

SQL Syntax error. Where is my syntatic mistake?

I can't for the life of me spot my typo!
UPDATE orders o, orders_total_couponz otc
SET o.total_paid = o.total_paid - ( otc.converted_value * ( 1 + ( otc.tax_rate / 100 ) ) ),
SET o.total_paid_tax_incl = o.total_paid_tax_incl - ( otc.converted_value * ( 1 + ( otc.tax_rate / 100 ) ) ),
SET o.total_paid_tax_excl = o.total_paid_tax_excl - otc.converted_value,
SET o.total_paid_tax_real = o.total_paid_tax_real - ( otc.converted_value * ( 1 + ( otc.tax_rate / 100 ) ) ),
SET o.total_products = o.total_products - otc.converted_value,
SET o.total_products_wt = o.total_products_wt - ( otc.converted_value * ( 1 + ( otc.tax_rate / 100 ) ) )
WHERE o.id_order = otc.orders_id
error:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SET o.total_paid_tax_incl = o.total_paid_tax_incl - ( otc.converted_value * ( 1 ' at line 3
Use the set keyword only once, and comma-separate the values to set:
UPDATE orders o, orders_total_couponz otc
SET o.total_paid = o.total_paid - ( otc.converted_value * ( 1 + ( otc.tax_rate / 100 ) ) ),
o.total_paid_tax_incl = o.total_paid_tax_incl - ( otc.converted_value * ( 1 + ( otc.tax_rate / 100 ) ) ),
o.total_paid_tax_excl = o.total_paid_tax_excl - otc.converted_value,
o.total_paid_tax_real = o.total_paid_tax_real - ( otc.converted_value * ( 1 + ( otc.tax_rate / 100 ) ) ),
o.total_products = o.total_products - otc.converted_value,
o.total_products_wt = o.total_products_wt - ( otc.converted_value * ( 1 + ( otc.tax_rate / 100 ) ) )
WHERE o.id_order = otc.orders_id
Do not use SET again and again. Use command like:
UPDATE orders o, orders_total_couponz otc
SET o.total_paid = o.total_paid - ( otc.converted_value * ( 1 + ( otc.tax_rate / 100 ) ) ),
o.total_paid_tax_incl = o.total_paid_tax_incl - ( otc.converted_value * ( 1 + ( otc.tax_rate / 100 ) ) ),
o.total_paid_tax_excl = o.total_paid_tax_excl - otc.converted_value,
o.total_paid_tax_real = o.total_paid_tax_real - ( otc.converted_value * ( 1 + ( otc.tax_rate / 100 ) ) ),
o.total_products = o.total_products - otc.converted_value,
o.total_products_wt = o.total_products_wt - ( otc.converted_value * ( 1 + ( otc.tax_rate / 100 ) ) )
WHERE o.id_order = otc.orders_id