Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

IF statement in SQL not correct

In the following SQL Statement I have to include an IF statement. I think that I have got it wrong. The part is if REPCODE = 'RTN' then 'C' ELSE S AS SALESTYPE,


SELECT 
pos_universal_code as TERRITID3, retailer AS TERRNAME4, '' as TERRITID1, '' as TERRNAME1, '' as TERRITID2, '' as TERRNAME2, DATA_TYPE_FREE_COLUMN_1 as REPCODE, DATA_TYPE_FREE_COLUMN_2 as REPNAME, '1' as BRANCHNUM, '1' as BRANCH, EXTERNAL_SHOPPING_CHANNEL as SALESCHAN, CUSTOMER_FREE_COLUMN_1 as CUSTID, '' as CUSTNAME1, '' as CUSTNAME2, '' as CUSTADD1, '' as CUSTADD2, '' as CUSTADD3, '' as ZIPCODE, '' as LEGALID, '' as PHONE, '' as MOBILE, '' as EMAIL, '' as CLUBMAT, '' as TXNID, TIME_FREE_COLUMN_1 AS IDTRAN, if REPCODE = 'RTN' then 'C' ELSE S AS SALESTYPE, 'S' as SALESTYPE, period_end_date as DATE, retailer_product_code as CODE,  as DESCRIPTION, '' as GENCOD, '' as IDPROD, '' as PRODTYPE, SOLD_QUANTITY_IN_UNITS As QTY, SOLD_AMOUNT_IN_LOCAL_CURRENCY As AMOUNT, EAN_UPC_CODE As BARCODE, '' as MATERIAL_NUMBER, '' as CODE_PACK, '' as FREE, 'GB' as CODE_PAYS, 'GBP' as CODE_DEVISE, FORMAT_DATE("%Y%m%d",CURRENT_DATE()) as TIME FROM `emea-datafoundat-gbl-emea-pd.d_sellout_warehouse_eu_pd.t_warehouse_sellout_v1` WHERE YEAR = 2021 AND loreal_market_flag LIKE '%L%' AND country_code IN ("GB","IE") AND DIVISION LIKE '%ACD%' AND UPPER(DATA_FILE_PROVIDER) LIKE '%PYTHON_UKI%' AND PERIOD_END_DATE = 20211009

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial