Avatar of Murray Brown
Murray Brown
Flag 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

SQL

Avatar of undefined
Last Comment
Éric Moreau

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Éric Moreau

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck