Case Expression Issue in SQL
I am using a IF statement and using a case statement to do that. When i do so, I get an error.
Basically, if the security type = 'Currency Future.', i want to output it as 'NetDetail' else 'Detail'
The SQL statement looks like this:
SELECT `Desk`, `VT_id`, `BloombergID`,`Id_Type`,`Position` ,`Price`, `positions_desk`.`Multiplier`,`CCY`,`business_date`,`APAC_Exposures_Map`.`Equity_Index`,`APAC_Exposures_Map`.`Security_Type`,`APAC_Exposures_Map`.`Leverage`, IF(Id_Type !='FWD',COALESCE(`APAC_Exposures_Map`.`Expiry`, `CBBC_Static_Data`.`Expiration_date`), STR_TO_DATE(SUBSTRING(`VT_id`, 7, 6),'%y%m%d') ) AS `Expiration_date`, `CBBC_Static_Data`.`Strike`
FROM `risk_source`.`positions_desk`,
(CASE
WHEN (`APAC_Exposures_Map`.`Security_Type`) THEN 'NetDetail'
ELSE 'Detail'
END) AS `Record_Type`
LEFT JOIN (`risk`.`APAC_Exposures_Map`) ON`positions_desk`.`BloombergID`=UPPER(`APAC_Exposures_Map`.`BBG_Ticker`)
LEFT JOIN (`risk_source`.`CBBC_Static_Data`) ON LEFT(`positions_desk`.`BloombergID`,5) =`CBBC_Static_Data`.`CBBC_Name`
WHERE business_date= ? AND (Id_Type='FUT') AND Desk NOT IN ('HKCOI')
The error looks like this:
<e>Query: SELECT `Desk`, `VT_id`, `BloombergID`,`Id_Type`,`Position` ,`Price`, `positions_desk`.`Multiplier`,`CCY`,`business_date`,`APAC_E...
Error Code: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'CASE
WHEN (`APAC_Exposures_Map`.`Security_Type`) THEN 'NetDetail'
' at line 3
sql mariadb
add a comment |
I am using a IF statement and using a case statement to do that. When i do so, I get an error.
Basically, if the security type = 'Currency Future.', i want to output it as 'NetDetail' else 'Detail'
The SQL statement looks like this:
SELECT `Desk`, `VT_id`, `BloombergID`,`Id_Type`,`Position` ,`Price`, `positions_desk`.`Multiplier`,`CCY`,`business_date`,`APAC_Exposures_Map`.`Equity_Index`,`APAC_Exposures_Map`.`Security_Type`,`APAC_Exposures_Map`.`Leverage`, IF(Id_Type !='FWD',COALESCE(`APAC_Exposures_Map`.`Expiry`, `CBBC_Static_Data`.`Expiration_date`), STR_TO_DATE(SUBSTRING(`VT_id`, 7, 6),'%y%m%d') ) AS `Expiration_date`, `CBBC_Static_Data`.`Strike`
FROM `risk_source`.`positions_desk`,
(CASE
WHEN (`APAC_Exposures_Map`.`Security_Type`) THEN 'NetDetail'
ELSE 'Detail'
END) AS `Record_Type`
LEFT JOIN (`risk`.`APAC_Exposures_Map`) ON`positions_desk`.`BloombergID`=UPPER(`APAC_Exposures_Map`.`BBG_Ticker`)
LEFT JOIN (`risk_source`.`CBBC_Static_Data`) ON LEFT(`positions_desk`.`BloombergID`,5) =`CBBC_Static_Data`.`CBBC_Name`
WHERE business_date= ? AND (Id_Type='FUT') AND Desk NOT IN ('HKCOI')
The error looks like this:
<e>Query: SELECT `Desk`, `VT_id`, `BloombergID`,`Id_Type`,`Position` ,`Price`, `positions_desk`.`Multiplier`,`CCY`,`business_date`,`APAC_E...
Error Code: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'CASE
WHEN (`APAC_Exposures_Map`.`Security_Type`) THEN 'NetDetail'
' at line 3
sql mariadb
what is your condition to check?
– fa06
Nov 23 '18 at 6:52
add a comment |
I am using a IF statement and using a case statement to do that. When i do so, I get an error.
Basically, if the security type = 'Currency Future.', i want to output it as 'NetDetail' else 'Detail'
The SQL statement looks like this:
SELECT `Desk`, `VT_id`, `BloombergID`,`Id_Type`,`Position` ,`Price`, `positions_desk`.`Multiplier`,`CCY`,`business_date`,`APAC_Exposures_Map`.`Equity_Index`,`APAC_Exposures_Map`.`Security_Type`,`APAC_Exposures_Map`.`Leverage`, IF(Id_Type !='FWD',COALESCE(`APAC_Exposures_Map`.`Expiry`, `CBBC_Static_Data`.`Expiration_date`), STR_TO_DATE(SUBSTRING(`VT_id`, 7, 6),'%y%m%d') ) AS `Expiration_date`, `CBBC_Static_Data`.`Strike`
FROM `risk_source`.`positions_desk`,
(CASE
WHEN (`APAC_Exposures_Map`.`Security_Type`) THEN 'NetDetail'
ELSE 'Detail'
END) AS `Record_Type`
LEFT JOIN (`risk`.`APAC_Exposures_Map`) ON`positions_desk`.`BloombergID`=UPPER(`APAC_Exposures_Map`.`BBG_Ticker`)
LEFT JOIN (`risk_source`.`CBBC_Static_Data`) ON LEFT(`positions_desk`.`BloombergID`,5) =`CBBC_Static_Data`.`CBBC_Name`
WHERE business_date= ? AND (Id_Type='FUT') AND Desk NOT IN ('HKCOI')
The error looks like this:
<e>Query: SELECT `Desk`, `VT_id`, `BloombergID`,`Id_Type`,`Position` ,`Price`, `positions_desk`.`Multiplier`,`CCY`,`business_date`,`APAC_E...
Error Code: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'CASE
WHEN (`APAC_Exposures_Map`.`Security_Type`) THEN 'NetDetail'
' at line 3
sql mariadb
I am using a IF statement and using a case statement to do that. When i do so, I get an error.
Basically, if the security type = 'Currency Future.', i want to output it as 'NetDetail' else 'Detail'
The SQL statement looks like this:
SELECT `Desk`, `VT_id`, `BloombergID`,`Id_Type`,`Position` ,`Price`, `positions_desk`.`Multiplier`,`CCY`,`business_date`,`APAC_Exposures_Map`.`Equity_Index`,`APAC_Exposures_Map`.`Security_Type`,`APAC_Exposures_Map`.`Leverage`, IF(Id_Type !='FWD',COALESCE(`APAC_Exposures_Map`.`Expiry`, `CBBC_Static_Data`.`Expiration_date`), STR_TO_DATE(SUBSTRING(`VT_id`, 7, 6),'%y%m%d') ) AS `Expiration_date`, `CBBC_Static_Data`.`Strike`
FROM `risk_source`.`positions_desk`,
(CASE
WHEN (`APAC_Exposures_Map`.`Security_Type`) THEN 'NetDetail'
ELSE 'Detail'
END) AS `Record_Type`
LEFT JOIN (`risk`.`APAC_Exposures_Map`) ON`positions_desk`.`BloombergID`=UPPER(`APAC_Exposures_Map`.`BBG_Ticker`)
LEFT JOIN (`risk_source`.`CBBC_Static_Data`) ON LEFT(`positions_desk`.`BloombergID`,5) =`CBBC_Static_Data`.`CBBC_Name`
WHERE business_date= ? AND (Id_Type='FUT') AND Desk NOT IN ('HKCOI')
The error looks like this:
<e>Query: SELECT `Desk`, `VT_id`, `BloombergID`,`Id_Type`,`Position` ,`Price`, `positions_desk`.`Multiplier`,`CCY`,`business_date`,`APAC_E...
Error Code: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'CASE
WHEN (`APAC_Exposures_Map`.`Security_Type`) THEN 'NetDetail'
' at line 3
sql mariadb
sql mariadb
edited Nov 23 '18 at 12:35
Gordon Linoff
791k35315419
791k35315419
asked Nov 23 '18 at 6:49
lakeshlakesh
15.6k50141234
15.6k50141234
what is your condition to check?
– fa06
Nov 23 '18 at 6:52
add a comment |
what is your condition to check?
– fa06
Nov 23 '18 at 6:52
what is your condition to check?
– fa06
Nov 23 '18 at 6:52
what is your condition to check?
– fa06
Nov 23 '18 at 6:52
add a comment |
4 Answers
4
active
oldest
votes
You need to specify your condition
SELECT `Desk`, `VT_id`, `BloombergID`,`Id_Type`,`Position` ,`Price`, `positions_desk`.`Multiplier`,`CCY`,`business_date`,`APAC_Exposures_Map`.`Equity_Index`,`APAC_Exposures_Map`.`Security_Type`,`APAC_Exposures_Map`.`Leverage`, IF(Id_Type !='FWD',COALESCE(`APAC_Exposures_Map`.`Expiry`, `CBBC_Static_Data`.`Expiration_date`), STR_TO_DATE(SUBSTRING(`VT_id`, 7, 6),'%y%m%d') ) AS `Expiration_date`, `CBBC_Static_Data`.`Strike`
,
CASE WHEN `APAC_Exposures_Map`.`Security_Type`='YOUR Condition' THEN 'NetDetail'
ELSE 'Detail'
END AS `Record_Type` FROM `risk_source`.`positions_desk`
LEFT JOIN (`risk`.`APAC_Exposures_Map`) ON`positions_desk`.`BloombergID`=UPPER(`APAC_Exposures_Map`.`BBG_Ticker`)
LEFT JOIN (`risk_source`.`CBBC_Static_Data`) ON LEFT(`positions_desk`.`BloombergID`,5) =`CBBC_Static_Data`.`CBBC_Name`
WHERE business_date= ? AND (Id_Type='FUT') AND Desk NOT IN ('HKCOI')
add a comment |
you have missed case when statement condition
case when APAC_Exposures_Map
.Security_Type
= //need conditional value here and this selection will before table name
SELECT `Desk`, `VT_id`, `BloombergID`,`Id_Type`,`Position` ,`Price`,
`positions_desk`.`Multiplier`,`CCY`,`business_date`,
`APAC_Exposures_Map`.`Equity_Index`,`APAC_Exposures_Map`.`Security_Type`,
`APAC_Exposures_Map`.`Leverage`,
IF(Id_Type !='FWD',COALESCE(`APAC_Exposures_Map`.`Expiry`, `CBBC_Static_Data`.`Expiration_date`),
STR_TO_DATE(SUBSTRING(`VT_id`, 7, 6),'%y%m%d') ) AS `Expiration_date`,
`CBBC_Static_Data`.`Strike`,
(CASE WHEN (`APAC_Exposures_Map`.`Security_Type`='need value') THEN 'NetDetail' ELSE 'Detail'
END) AS `Record_Type`
FROM `risk_source`.`positions_desk`
LEFT JOIN (`risk`.`APAC_Exposures_Map`) ON`positions_desk`.`BloombergID`=UPPER(`APAC_Exposures_Map`.`BBG_Ticker`)
LEFT JOIN (`risk_source`.`CBBC_Static_Data`) ON LEFT(`positions_desk`.`BloombergID`,5) =`CBBC_Static_Data`.`CBBC_Name`
WHERE business_date= ? AND (Id_Type='FUT') AND Desk NOT IN ('HKCOI')
add a comment |
You forgot something:
(CASE
WHEN (`APAC_Exposures_Map`.`Security_Type` = 'Currency Future') THEN 'NetDetail'
ELSE 'Detail'
END) AS `Record_Type`
The condition should be:
`APAC_Exposures_Map`.`Security_Type` = 'Currency Future'
add a comment |
Could you test it?
SELECT `Desk`, `VT_id`, `BloombergID`,`Id_Type`,`Position` ,`Price`, `positions_desk`.`Multiplier`,`CCY`,`business_date`,`APAC_Exposures_Map`.`Equity_Index`,`APAC_Exposures_Map`.`Security_Type`,`APAC_Exposures_Map`.`Leverage`, CASE WHEN(Id_Type !='FWD' THEN COALESCE(`APAC_Exposures_Map`.`Expiry`, `CBBC_Static_Data`.`Expiration_date`), STR_TO_DATE(SUBSTRING(`VT_id`, 7, 6),'%y%m%d') ) ELSE GETDATE() AS `Expiration_date`, `CBBC_Static_Data`.`Strike`
FROM `risk_source`.`positions_desk`,
(CASE
WHEN (`APAC_Exposures_Map`.`Security_Type`) THEN 'NetDetail'
ELSE 'Detail'
END) AS `Record_Type`
LEFT JOIN (`risk`.`APAC_Exposures_Map`) ON`positions_desk`.`BloombergID`=UPPER(`APAC_Exposures_Map`.`BBG_Ticker`)
LEFT JOIN (`risk_source`.`CBBC_Static_Data`) ON LEFT(`positions_desk`.`BloombergID`,5) =`CBBC_Static_Data`.`CBBC_Name`
WHERE business_date= ? AND (Id_Type='FUT') AND Desk NOT IN ('HKCOI')
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53441869%2fcase-expression-issue-in-sql%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
You need to specify your condition
SELECT `Desk`, `VT_id`, `BloombergID`,`Id_Type`,`Position` ,`Price`, `positions_desk`.`Multiplier`,`CCY`,`business_date`,`APAC_Exposures_Map`.`Equity_Index`,`APAC_Exposures_Map`.`Security_Type`,`APAC_Exposures_Map`.`Leverage`, IF(Id_Type !='FWD',COALESCE(`APAC_Exposures_Map`.`Expiry`, `CBBC_Static_Data`.`Expiration_date`), STR_TO_DATE(SUBSTRING(`VT_id`, 7, 6),'%y%m%d') ) AS `Expiration_date`, `CBBC_Static_Data`.`Strike`
,
CASE WHEN `APAC_Exposures_Map`.`Security_Type`='YOUR Condition' THEN 'NetDetail'
ELSE 'Detail'
END AS `Record_Type` FROM `risk_source`.`positions_desk`
LEFT JOIN (`risk`.`APAC_Exposures_Map`) ON`positions_desk`.`BloombergID`=UPPER(`APAC_Exposures_Map`.`BBG_Ticker`)
LEFT JOIN (`risk_source`.`CBBC_Static_Data`) ON LEFT(`positions_desk`.`BloombergID`,5) =`CBBC_Static_Data`.`CBBC_Name`
WHERE business_date= ? AND (Id_Type='FUT') AND Desk NOT IN ('HKCOI')
add a comment |
You need to specify your condition
SELECT `Desk`, `VT_id`, `BloombergID`,`Id_Type`,`Position` ,`Price`, `positions_desk`.`Multiplier`,`CCY`,`business_date`,`APAC_Exposures_Map`.`Equity_Index`,`APAC_Exposures_Map`.`Security_Type`,`APAC_Exposures_Map`.`Leverage`, IF(Id_Type !='FWD',COALESCE(`APAC_Exposures_Map`.`Expiry`, `CBBC_Static_Data`.`Expiration_date`), STR_TO_DATE(SUBSTRING(`VT_id`, 7, 6),'%y%m%d') ) AS `Expiration_date`, `CBBC_Static_Data`.`Strike`
,
CASE WHEN `APAC_Exposures_Map`.`Security_Type`='YOUR Condition' THEN 'NetDetail'
ELSE 'Detail'
END AS `Record_Type` FROM `risk_source`.`positions_desk`
LEFT JOIN (`risk`.`APAC_Exposures_Map`) ON`positions_desk`.`BloombergID`=UPPER(`APAC_Exposures_Map`.`BBG_Ticker`)
LEFT JOIN (`risk_source`.`CBBC_Static_Data`) ON LEFT(`positions_desk`.`BloombergID`,5) =`CBBC_Static_Data`.`CBBC_Name`
WHERE business_date= ? AND (Id_Type='FUT') AND Desk NOT IN ('HKCOI')
add a comment |
You need to specify your condition
SELECT `Desk`, `VT_id`, `BloombergID`,`Id_Type`,`Position` ,`Price`, `positions_desk`.`Multiplier`,`CCY`,`business_date`,`APAC_Exposures_Map`.`Equity_Index`,`APAC_Exposures_Map`.`Security_Type`,`APAC_Exposures_Map`.`Leverage`, IF(Id_Type !='FWD',COALESCE(`APAC_Exposures_Map`.`Expiry`, `CBBC_Static_Data`.`Expiration_date`), STR_TO_DATE(SUBSTRING(`VT_id`, 7, 6),'%y%m%d') ) AS `Expiration_date`, `CBBC_Static_Data`.`Strike`
,
CASE WHEN `APAC_Exposures_Map`.`Security_Type`='YOUR Condition' THEN 'NetDetail'
ELSE 'Detail'
END AS `Record_Type` FROM `risk_source`.`positions_desk`
LEFT JOIN (`risk`.`APAC_Exposures_Map`) ON`positions_desk`.`BloombergID`=UPPER(`APAC_Exposures_Map`.`BBG_Ticker`)
LEFT JOIN (`risk_source`.`CBBC_Static_Data`) ON LEFT(`positions_desk`.`BloombergID`,5) =`CBBC_Static_Data`.`CBBC_Name`
WHERE business_date= ? AND (Id_Type='FUT') AND Desk NOT IN ('HKCOI')
You need to specify your condition
SELECT `Desk`, `VT_id`, `BloombergID`,`Id_Type`,`Position` ,`Price`, `positions_desk`.`Multiplier`,`CCY`,`business_date`,`APAC_Exposures_Map`.`Equity_Index`,`APAC_Exposures_Map`.`Security_Type`,`APAC_Exposures_Map`.`Leverage`, IF(Id_Type !='FWD',COALESCE(`APAC_Exposures_Map`.`Expiry`, `CBBC_Static_Data`.`Expiration_date`), STR_TO_DATE(SUBSTRING(`VT_id`, 7, 6),'%y%m%d') ) AS `Expiration_date`, `CBBC_Static_Data`.`Strike`
,
CASE WHEN `APAC_Exposures_Map`.`Security_Type`='YOUR Condition' THEN 'NetDetail'
ELSE 'Detail'
END AS `Record_Type` FROM `risk_source`.`positions_desk`
LEFT JOIN (`risk`.`APAC_Exposures_Map`) ON`positions_desk`.`BloombergID`=UPPER(`APAC_Exposures_Map`.`BBG_Ticker`)
LEFT JOIN (`risk_source`.`CBBC_Static_Data`) ON LEFT(`positions_desk`.`BloombergID`,5) =`CBBC_Static_Data`.`CBBC_Name`
WHERE business_date= ? AND (Id_Type='FUT') AND Desk NOT IN ('HKCOI')
edited Nov 23 '18 at 7:04
answered Nov 23 '18 at 6:53
fa06fa06
18k21018
18k21018
add a comment |
add a comment |
you have missed case when statement condition
case when APAC_Exposures_Map
.Security_Type
= //need conditional value here and this selection will before table name
SELECT `Desk`, `VT_id`, `BloombergID`,`Id_Type`,`Position` ,`Price`,
`positions_desk`.`Multiplier`,`CCY`,`business_date`,
`APAC_Exposures_Map`.`Equity_Index`,`APAC_Exposures_Map`.`Security_Type`,
`APAC_Exposures_Map`.`Leverage`,
IF(Id_Type !='FWD',COALESCE(`APAC_Exposures_Map`.`Expiry`, `CBBC_Static_Data`.`Expiration_date`),
STR_TO_DATE(SUBSTRING(`VT_id`, 7, 6),'%y%m%d') ) AS `Expiration_date`,
`CBBC_Static_Data`.`Strike`,
(CASE WHEN (`APAC_Exposures_Map`.`Security_Type`='need value') THEN 'NetDetail' ELSE 'Detail'
END) AS `Record_Type`
FROM `risk_source`.`positions_desk`
LEFT JOIN (`risk`.`APAC_Exposures_Map`) ON`positions_desk`.`BloombergID`=UPPER(`APAC_Exposures_Map`.`BBG_Ticker`)
LEFT JOIN (`risk_source`.`CBBC_Static_Data`) ON LEFT(`positions_desk`.`BloombergID`,5) =`CBBC_Static_Data`.`CBBC_Name`
WHERE business_date= ? AND (Id_Type='FUT') AND Desk NOT IN ('HKCOI')
add a comment |
you have missed case when statement condition
case when APAC_Exposures_Map
.Security_Type
= //need conditional value here and this selection will before table name
SELECT `Desk`, `VT_id`, `BloombergID`,`Id_Type`,`Position` ,`Price`,
`positions_desk`.`Multiplier`,`CCY`,`business_date`,
`APAC_Exposures_Map`.`Equity_Index`,`APAC_Exposures_Map`.`Security_Type`,
`APAC_Exposures_Map`.`Leverage`,
IF(Id_Type !='FWD',COALESCE(`APAC_Exposures_Map`.`Expiry`, `CBBC_Static_Data`.`Expiration_date`),
STR_TO_DATE(SUBSTRING(`VT_id`, 7, 6),'%y%m%d') ) AS `Expiration_date`,
`CBBC_Static_Data`.`Strike`,
(CASE WHEN (`APAC_Exposures_Map`.`Security_Type`='need value') THEN 'NetDetail' ELSE 'Detail'
END) AS `Record_Type`
FROM `risk_source`.`positions_desk`
LEFT JOIN (`risk`.`APAC_Exposures_Map`) ON`positions_desk`.`BloombergID`=UPPER(`APAC_Exposures_Map`.`BBG_Ticker`)
LEFT JOIN (`risk_source`.`CBBC_Static_Data`) ON LEFT(`positions_desk`.`BloombergID`,5) =`CBBC_Static_Data`.`CBBC_Name`
WHERE business_date= ? AND (Id_Type='FUT') AND Desk NOT IN ('HKCOI')
add a comment |
you have missed case when statement condition
case when APAC_Exposures_Map
.Security_Type
= //need conditional value here and this selection will before table name
SELECT `Desk`, `VT_id`, `BloombergID`,`Id_Type`,`Position` ,`Price`,
`positions_desk`.`Multiplier`,`CCY`,`business_date`,
`APAC_Exposures_Map`.`Equity_Index`,`APAC_Exposures_Map`.`Security_Type`,
`APAC_Exposures_Map`.`Leverage`,
IF(Id_Type !='FWD',COALESCE(`APAC_Exposures_Map`.`Expiry`, `CBBC_Static_Data`.`Expiration_date`),
STR_TO_DATE(SUBSTRING(`VT_id`, 7, 6),'%y%m%d') ) AS `Expiration_date`,
`CBBC_Static_Data`.`Strike`,
(CASE WHEN (`APAC_Exposures_Map`.`Security_Type`='need value') THEN 'NetDetail' ELSE 'Detail'
END) AS `Record_Type`
FROM `risk_source`.`positions_desk`
LEFT JOIN (`risk`.`APAC_Exposures_Map`) ON`positions_desk`.`BloombergID`=UPPER(`APAC_Exposures_Map`.`BBG_Ticker`)
LEFT JOIN (`risk_source`.`CBBC_Static_Data`) ON LEFT(`positions_desk`.`BloombergID`,5) =`CBBC_Static_Data`.`CBBC_Name`
WHERE business_date= ? AND (Id_Type='FUT') AND Desk NOT IN ('HKCOI')
you have missed case when statement condition
case when APAC_Exposures_Map
.Security_Type
= //need conditional value here and this selection will before table name
SELECT `Desk`, `VT_id`, `BloombergID`,`Id_Type`,`Position` ,`Price`,
`positions_desk`.`Multiplier`,`CCY`,`business_date`,
`APAC_Exposures_Map`.`Equity_Index`,`APAC_Exposures_Map`.`Security_Type`,
`APAC_Exposures_Map`.`Leverage`,
IF(Id_Type !='FWD',COALESCE(`APAC_Exposures_Map`.`Expiry`, `CBBC_Static_Data`.`Expiration_date`),
STR_TO_DATE(SUBSTRING(`VT_id`, 7, 6),'%y%m%d') ) AS `Expiration_date`,
`CBBC_Static_Data`.`Strike`,
(CASE WHEN (`APAC_Exposures_Map`.`Security_Type`='need value') THEN 'NetDetail' ELSE 'Detail'
END) AS `Record_Type`
FROM `risk_source`.`positions_desk`
LEFT JOIN (`risk`.`APAC_Exposures_Map`) ON`positions_desk`.`BloombergID`=UPPER(`APAC_Exposures_Map`.`BBG_Ticker`)
LEFT JOIN (`risk_source`.`CBBC_Static_Data`) ON LEFT(`positions_desk`.`BloombergID`,5) =`CBBC_Static_Data`.`CBBC_Name`
WHERE business_date= ? AND (Id_Type='FUT') AND Desk NOT IN ('HKCOI')
edited Nov 23 '18 at 7:09
answered Nov 23 '18 at 6:53
Zaynul Abadin TuhinZaynul Abadin Tuhin
18.2k21134
18.2k21134
add a comment |
add a comment |
You forgot something:
(CASE
WHEN (`APAC_Exposures_Map`.`Security_Type` = 'Currency Future') THEN 'NetDetail'
ELSE 'Detail'
END) AS `Record_Type`
The condition should be:
`APAC_Exposures_Map`.`Security_Type` = 'Currency Future'
add a comment |
You forgot something:
(CASE
WHEN (`APAC_Exposures_Map`.`Security_Type` = 'Currency Future') THEN 'NetDetail'
ELSE 'Detail'
END) AS `Record_Type`
The condition should be:
`APAC_Exposures_Map`.`Security_Type` = 'Currency Future'
add a comment |
You forgot something:
(CASE
WHEN (`APAC_Exposures_Map`.`Security_Type` = 'Currency Future') THEN 'NetDetail'
ELSE 'Detail'
END) AS `Record_Type`
The condition should be:
`APAC_Exposures_Map`.`Security_Type` = 'Currency Future'
You forgot something:
(CASE
WHEN (`APAC_Exposures_Map`.`Security_Type` = 'Currency Future') THEN 'NetDetail'
ELSE 'Detail'
END) AS `Record_Type`
The condition should be:
`APAC_Exposures_Map`.`Security_Type` = 'Currency Future'
answered Nov 23 '18 at 6:52
forpasforpas
18.5k3728
18.5k3728
add a comment |
add a comment |
Could you test it?
SELECT `Desk`, `VT_id`, `BloombergID`,`Id_Type`,`Position` ,`Price`, `positions_desk`.`Multiplier`,`CCY`,`business_date`,`APAC_Exposures_Map`.`Equity_Index`,`APAC_Exposures_Map`.`Security_Type`,`APAC_Exposures_Map`.`Leverage`, CASE WHEN(Id_Type !='FWD' THEN COALESCE(`APAC_Exposures_Map`.`Expiry`, `CBBC_Static_Data`.`Expiration_date`), STR_TO_DATE(SUBSTRING(`VT_id`, 7, 6),'%y%m%d') ) ELSE GETDATE() AS `Expiration_date`, `CBBC_Static_Data`.`Strike`
FROM `risk_source`.`positions_desk`,
(CASE
WHEN (`APAC_Exposures_Map`.`Security_Type`) THEN 'NetDetail'
ELSE 'Detail'
END) AS `Record_Type`
LEFT JOIN (`risk`.`APAC_Exposures_Map`) ON`positions_desk`.`BloombergID`=UPPER(`APAC_Exposures_Map`.`BBG_Ticker`)
LEFT JOIN (`risk_source`.`CBBC_Static_Data`) ON LEFT(`positions_desk`.`BloombergID`,5) =`CBBC_Static_Data`.`CBBC_Name`
WHERE business_date= ? AND (Id_Type='FUT') AND Desk NOT IN ('HKCOI')
add a comment |
Could you test it?
SELECT `Desk`, `VT_id`, `BloombergID`,`Id_Type`,`Position` ,`Price`, `positions_desk`.`Multiplier`,`CCY`,`business_date`,`APAC_Exposures_Map`.`Equity_Index`,`APAC_Exposures_Map`.`Security_Type`,`APAC_Exposures_Map`.`Leverage`, CASE WHEN(Id_Type !='FWD' THEN COALESCE(`APAC_Exposures_Map`.`Expiry`, `CBBC_Static_Data`.`Expiration_date`), STR_TO_DATE(SUBSTRING(`VT_id`, 7, 6),'%y%m%d') ) ELSE GETDATE() AS `Expiration_date`, `CBBC_Static_Data`.`Strike`
FROM `risk_source`.`positions_desk`,
(CASE
WHEN (`APAC_Exposures_Map`.`Security_Type`) THEN 'NetDetail'
ELSE 'Detail'
END) AS `Record_Type`
LEFT JOIN (`risk`.`APAC_Exposures_Map`) ON`positions_desk`.`BloombergID`=UPPER(`APAC_Exposures_Map`.`BBG_Ticker`)
LEFT JOIN (`risk_source`.`CBBC_Static_Data`) ON LEFT(`positions_desk`.`BloombergID`,5) =`CBBC_Static_Data`.`CBBC_Name`
WHERE business_date= ? AND (Id_Type='FUT') AND Desk NOT IN ('HKCOI')
add a comment |
Could you test it?
SELECT `Desk`, `VT_id`, `BloombergID`,`Id_Type`,`Position` ,`Price`, `positions_desk`.`Multiplier`,`CCY`,`business_date`,`APAC_Exposures_Map`.`Equity_Index`,`APAC_Exposures_Map`.`Security_Type`,`APAC_Exposures_Map`.`Leverage`, CASE WHEN(Id_Type !='FWD' THEN COALESCE(`APAC_Exposures_Map`.`Expiry`, `CBBC_Static_Data`.`Expiration_date`), STR_TO_DATE(SUBSTRING(`VT_id`, 7, 6),'%y%m%d') ) ELSE GETDATE() AS `Expiration_date`, `CBBC_Static_Data`.`Strike`
FROM `risk_source`.`positions_desk`,
(CASE
WHEN (`APAC_Exposures_Map`.`Security_Type`) THEN 'NetDetail'
ELSE 'Detail'
END) AS `Record_Type`
LEFT JOIN (`risk`.`APAC_Exposures_Map`) ON`positions_desk`.`BloombergID`=UPPER(`APAC_Exposures_Map`.`BBG_Ticker`)
LEFT JOIN (`risk_source`.`CBBC_Static_Data`) ON LEFT(`positions_desk`.`BloombergID`,5) =`CBBC_Static_Data`.`CBBC_Name`
WHERE business_date= ? AND (Id_Type='FUT') AND Desk NOT IN ('HKCOI')
Could you test it?
SELECT `Desk`, `VT_id`, `BloombergID`,`Id_Type`,`Position` ,`Price`, `positions_desk`.`Multiplier`,`CCY`,`business_date`,`APAC_Exposures_Map`.`Equity_Index`,`APAC_Exposures_Map`.`Security_Type`,`APAC_Exposures_Map`.`Leverage`, CASE WHEN(Id_Type !='FWD' THEN COALESCE(`APAC_Exposures_Map`.`Expiry`, `CBBC_Static_Data`.`Expiration_date`), STR_TO_DATE(SUBSTRING(`VT_id`, 7, 6),'%y%m%d') ) ELSE GETDATE() AS `Expiration_date`, `CBBC_Static_Data`.`Strike`
FROM `risk_source`.`positions_desk`,
(CASE
WHEN (`APAC_Exposures_Map`.`Security_Type`) THEN 'NetDetail'
ELSE 'Detail'
END) AS `Record_Type`
LEFT JOIN (`risk`.`APAC_Exposures_Map`) ON`positions_desk`.`BloombergID`=UPPER(`APAC_Exposures_Map`.`BBG_Ticker`)
LEFT JOIN (`risk_source`.`CBBC_Static_Data`) ON LEFT(`positions_desk`.`BloombergID`,5) =`CBBC_Static_Data`.`CBBC_Name`
WHERE business_date= ? AND (Id_Type='FUT') AND Desk NOT IN ('HKCOI')
answered Nov 23 '18 at 6:57
kemal akoğlukemal akoğlu
14911
14911
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53441869%2fcase-expression-issue-in-sql%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
what is your condition to check?
– fa06
Nov 23 '18 at 6:52