mismatched input ')' expecting END - apache-pig

I need to create DMS_EPRPFL entity as shown by this pig script :
DMS_EPRPFL = FOREACH ORDER_EPSE_ENEE_ENR GENERATE
GROUP_EPSE_ENEE_ENR::IDT_GCP AS IDT_GCP,
GROUP_EPSE_ENEE_ENR::CD_FRM_JUR AS CD_FRM_JUR,
GROUP_EPSE_ENEE_ENR::DA_CRE_EPS AS DA_CRE_EPS,
GROUP_EPSE_ENEE_ENR::NO_SIREN AS NO_SIREN,
GROUP_EPSE_ENEE_ENR::CD_POST AS CD_POST,
GROUP_EPSE_ENEE_ENR::CD_OSCE_PAYS_FIS AS CD_OSCE_PAYS_FIS,
GROUP_EPSE_ENEE_ENR::CD_NAF AS CD_NAF,
GROUP_EPSE_ENEE_ENR::CD_NACE AS CD_NACE,
(CASE (GROUP_EPSE_ENEE_ENR::CD_AXE_MCH)
WHEN ('PLIB' OR 'ATPE' OR 'COMM') THEN 'P'
WHEN ('PME') THEN 'E'
WHEN ('AGRI') THEN 'A'
WHEN ('OBNL') THEN 'O'
WHEN ('COLL') THEN 'C'
WHEN ('EFIN') THEN 'B'
WHEN ('NONA' OR 'SCI') THEN 'X') AS CD_MARCHE,
GROUP_EPSE_ENEE_ENR::CD_AXE_SNIV_MCH AS CD_AXE_SNIV_MCH,
MIN(GROUP_EPSE_ENEE_ENR::A_PRM_CTR) AS A_PRM_CTR,
MIN(GROUP_EPSE_ENEE_ENR::A_PRM_CAV) AS A_PRM_CAV,
MIN(GROUP_EPSE_ENEE_ENR::A_PRPRE) AS A_PRPRE,
GROUP_EPSE_ENEE_ENR::CD_NOT AS CD_NOT;
The problem is about CD_MARCHE .In fact I need to generate it according to specific conditions and using the case operator.
When executing the script I have this error :
mismatched input ')' expecting END
in this line
WHEN ('NONA' OR 'SCI') THEN 'X') AS CD_MARCHE,
I can't find the problem there.
Thanks for your help

From
http://pig.apache.org/docs/latest/basic.html#arithmetic
CASE either takes
CASE expression [ WHEN value THEN value ]+ [ ELSE value ]? END
OR
CASE [ WHEN condition THEN value ]+ [ ELSE value ]? END
In your example, you're using the former but mixing condition (A OR B) where it only accepts value. Two changes needed.
Add "END" at the end of your case statement and use the latter CASE statement.
Rewrite
(CASE (field)
WHEN ( 'PLIB' OR 'ATPE' OR 'COMM' ) THEN 'P'
WHEN ('PME') THEN 'E'
...
WHEN ('NONA' OR 'SCI') THEN 'X') AS CD_MARCHE,
to
(CASE
WHEN (field in ('PLIB','ATPE','COMM') ) THEN 'P'
WHEN (field == 'PME') THEN 'E'
...
WHEN (field in ('NONA','SCI')) THEN 'X' END) AS CD_MARCHE,

Related

use sql case statement in a adoquery of delphi

so i want to calculate a sum of a field using adoquery and case statement in delphi ;
the code i use is this :
DataModule2.ADOQuery1_630.sql.clear;
DataModule2.ADOQuery1_630.sql.Add('select STATUT,case when month(DATE_PAI)=1 then sum(MT) else 0 end AS m');
DataModule2.ADOQuery1_630.sql.Add('from table');
DataModule2.ADOQuery1_630.sql.Add('where STATUT in( :dd ,:df) and TYPE_QUIT = :l ');
DataModule2.ADOQuery1_630.sql.Add('group by STATUT');
DataModule2.ADOQuery1_630.Parameters.ParamByName('dd').Value:=pm;
DataModule2.ADOQuery1_630.Parameters.ParamByName('df').Value:=pp;
DataModule2.ADOQuery1_630.Parameters.ParamByName('l').Value:=typeQ;
DataModule2.ADOQuery1_630.prepared := true;
DataModule2.ADOQuery1_630.open;
but i gest an error message :
syntax error operator absent in the expression case when
month(DATE_PAI)=1 then sum(MT) else 0 end
can any one help me please
Try to do :
(group SELECT and FROM in the same DataModule2.ADOQuery1_630.sql.Add())
DataModule2.ADOQuery1_630.sql.clear;
DataModule2.ADOQuery1_630.sql.Add('SELECT STATUT, SUM(case when month(DATE_PAI)=1 then MT ELSE 0 END) AS m FROM table');
DataModule2.ADOQuery1_630.sql.Add('WHERE STATUT in(:dd,:df) and TYPE_QUIT=:l');
DataModule2.ADOQuery1_630.sql.Add('GROUP BY STATUT');
//...

Is there a way to use a variable to comment out a line in the where clause?

I have a line in my WHERE clause that would be a nice added feature to be able to toggle. This way the end user doesn't have to run two reports. I haven't found anything like it so I'm thinking you cannot but maybe I am looking at the problem the wrong way and someone else knows a better way.
I have tried to run the code below with the last line as #AND and defining the variable as 'AND' & '--'giving me incorrect syntax error x2.
I also tried IS #NULL and defining the variable as 'NULL' & 'NOT NULL' giving me incorrect syntax error x2
SELECT
item_id
FROM
cba_item_location
WHERE
discontinued='Y'
AND qty_on_hand = '0'
AND (select abc_code from abc_miscdata where abc_code=item_id and abc_type='ITEM' and data_1 ='DISCON_ZERO_SENT') IS NULL
order by item_id
Example 1:
SELECT
item_id
FROM
cba_item_location
WHERE
discontinued='Y'
AND qty_on_hand = '0'
**#AND** (select abc_code from abc_miscdata where abc_code=item_id and abc_type='ITEM' and data_1 ='DISCON_ZERO_SENT') IS NULL
Example 2:
SELECT
item_id
FROM
cba_item_location
WHERE
discontinued='Y'
AND qty_on_hand = '0'
AND (select abc_code from abc_miscdata where abc_code=item_id and abc_type='ITEM' and data_1 ='DISCON_ZERO_SENT') IS **#NULL**
Any ideas?
Option 1: dynamic SQL
Option 2: include a flag into your WHERE clause which will switch it on and off
DECLARE #and bit = 0
IF (some condition) SET #and = 1
...
WHERE
discontinued='Y'
AND qty_on_hand = '0'
AND (#and = 1 AND (select abc_code from abc_miscdata where abc_code=item_id and abc_type='ITEM' and data_1 ='DISCON_ZERO_SENT') IS NULL)

SQL Server switch data to display something else

I am trying to figure out I can change the data on the fly.
This is my current query:
SELECT [EmployeeTC_No] AS "Employee TC#"
,[pye_nlast] AS "Name Last"
,[pye_nfirst] AS "Name First"
,[Dept] AS "Department"
,[pye_status] AS "Active"
,[HireDate] AS "Hire Date"
,[SeparationDate] AS "Separation Date"
FROM [testing].[dbo].[testing]
In the column of pye_status the data comes in as "A" or "T" and I want it to be "1" or "0".
I have tried to add a case statement trying to do some kind of switch but nothing appears to even get me close.
CASE/WHEN should do the trick:
,CASE WHEN [pye_status] = 'A' THEN 1
WHEN [pye_status] = 'T' THEN 0
ELSE NULL END AS "Active"
Or a simple case/when will work too:
, CASE [pye_status]
WHEN 'A' THEN 1
WHEN 'T' THEN 0
ELSE NULL END AS "Active"
Use CASE expression or IIF() function as
CASE WHEN [pye_status] = 'A' THEN 1 ELSE 0 END AS [Active]
OR
IIF([pye_status] = 'A', 1, 0) AS [Active]

Case in Select Query has syntax error

I want to return a boolean according to a condition on one of the column of my table. I tested it in SQL Server 2014 and it works, but I have no experience in Access.
This is the query I have at the moment, using Access 2007.
SELECT (CASE WHEN Type = 'C' THEN 1 ELSE 0 END) AS EstContrat
FROM Historique_EnTete
Type has the Text type.
I have translated the error message to :
"Syntax error (missing operator) in the expression << (CASE WHEN Type = 'C' THEN 1 ELSE 0 END) >>"
What am I missing?
In access you have IIF
SELECT IIF(Type = 'C', 1, 0 ) AS EstContrat
FROM Historique_EnTete
As Lamak say you also have SWITCH

SQL Error - The identifier that starts with..........is too long. Maximum lenght is 128

Below is my SQL query which is returning back error message
The identifier that starts with 'CASE WHEN PX_PAXWEB.COUNTRY = 'AUT' THEN >vw_POSTCODE.POSTCODE
WHEN PX_PAXWEB.COUNTRTY <> 'AUT' THEN vwPxPaxWe'
is too long. Maximum length is 128.
Msg 103, Level 15, State 4, Procedure vwRBARpt_AJ, Line 168
The identifier that starts with 'CASE WHEN AG_AGENTS.SALES_AREA_DESC = 'Int. – Inbound >Then vwPxPaxweb.SALES_AREA' is too long. Maximum length is 128."
Here's the SQL query:
CASE
WHEN AG_AGENTS.SALES_AREA_DESC = 'Dom. - NAT'
THEN [CASE
WHEN PX_PAXWEB.COUNTRY = 'AUT' THEN vw_POSTCODE.POSTCODE
WHEN PX_PAXWEB.COUNTRTY <> 'AUT' THEN vwPxPaxWeb.SALES_AREA
ELSE COALESCE (vw_POSTCODE.POSTCODE, vwPxPaxWeb.SALES_AREA, AG_AGENTS.SALES_AREA_DESC) ]
ELSE
[CASE WHEN AG_AGENTS.SALES_AREA_DESC = Int. – Inbound
THEN vwPxPaxweb.SALES_AREA
ELSE COALESCE(vwPxPaxweb.SALES_AREA, AG_AGENTS.SALES_AREA_DESC)]
END AS SALES_AREA_DESC_2
It took me formatting your code to realize it, but you need parentheses and not square brackets surrounding your cases. As you have it, it's trying to find a column/table/whatever that's named "[...your code...]", which is certainly too long.
Try doing it like below. Use () to separate the CASE. [] is used for identifires; like if you are using reserve word as column names or if your column names have spaces in it then to delimit them.
CASE WHEN AG_AGENTS.SALES_AREA_DESC = 'Dom. - NAT' THEN
(CASE WHEN PX_PAXWEB.COUNTRY = 'AUT' THEN vw_POSTCODE.POSTCODE
WHEN PX_PAXWEB.COUNTRTY <> 'AUT' THEN vwPxPaxWeb.SALES_AREA
ELSE COALESCE (vw_POSTCODE.POSTCODE,vwPxPaxWeb.SALES_AREA,AG_AGENTS.SALES_AREA_DESC)
)
ELSE
(CASE WHEN AG_AGENTS.SALES_AREA_DESC = 'Int. – Inbound' Then vwPxPaxweb.SALES_AREA
ELSE COALESCE( vwPxPaxweb.SALES_AREA,AG_AGENTS.SALES_AREA_DESC)
)
END AS SALES_AREA_DESC_2