0
 SELECT tu.begin_date, tm.MAGAZINE_ID,`MAGAZINE_NAME`, CASE WHEN ts.no_of_issues IS NULL THEN 1 ELSE ts.no_of_issues END AS Subscription_Type, 
 CASE WHEN 
   IF(tu.customer_currency = 'USD', 54 * tu.customer_currency) 
   ELSE IF(tu.customer_currency = 'CAD', 1.0250 * tu.customer_currency) 
   END AS sale_price_inr,
 tu.developer_proceeds as orginal_rate, tu.customer_currency as orginal_currency
 FROM `tbl_itunes_report` tu
 LEFT JOIN tbl_magazine_subscription ts ON ts.subscription_key = tu.sku_key
 LEFT JOIN tbl_magazine_issue ti ON ti.PurchaseKey = tu.sku_key AND ti.OS_SELECT = 0
 LEFT JOIN tbl_magazine tm ON tm.magazine_id = ts.magazine_id
 OR tm.magazine_id = ti.magazine_id
 WHERE `product_type_identifier` LIKE 'IA%'
 AND
 (
     ts.subscription_key IS NOT NULL
     OR ti.PurchaseKey IS NOT NULL
 )
 AND tu.begin_date >= '2012-04-01' AND tu.begin_date <= '2013-04-01'

This is my query. But i excecute this query i got an error that

 #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 ') ELSE IF(tu.customer_currency = 'CAD', 1.0250 * tu.customer_currency) END A' at line 3

if any one know this please help me. i am new to this

thanks in advance

2 Answers 2

2

Change

 ...
 CASE WHEN 
 IF(tu.customer_currency = 'USD', 54 * tu.customer_currency) 
 ELSE IF(tu.customer_currency = 'CAD', 1.0250 * tu.customer_currency) 
 END AS sale_price_inr
 ...

to

...
CASE WHEN tu.customer_currency = 'USD' THEN 54 * tu.customer_currency
     WHEN tu.customer_currency = 'CAD' THEN 1.0250 * tu.customer_currency 
 END AS sale_price_inr
...
Sign up to request clarification or add additional context in comments.

Comments

1

There is different syntax for IF statement and IF function, you are using IF function with syntax of IF Statement, please change below line

IF(tu.customer_currency = 'USD', 54 * tu.customer_currency) 
 ELSE IF(tu.customer_currency = 'CAD', 1.0250 * tu.customer_currency)

to

CASE WHEN tu.customer_currency = 'USD' THEN 54 * tu.customer_currency
     WHEN tu.customer_currency = 'CAD' THEN 1.0250 * tu.customer_currency 
 END AS sale_price_inr

OR

IF(tu.customer_currency = 'USD', 54 * tu.customer_currency, 1.0250 * tu.customer_currency)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.