Case Expression Issue in SQL












-2















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









share|improve this question

























  • what is your condition to check?

    – fa06
    Nov 23 '18 at 6:52
















-2















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









share|improve this question

























  • what is your condition to check?

    – fa06
    Nov 23 '18 at 6:52














-2












-2








-2








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









share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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



















  • 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












4 Answers
4






active

oldest

votes


















1














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')





share|improve this answer

































    1














    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')





    share|improve this answer

































      0














      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'





      share|improve this answer































        0














        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')





        share|improve this answer























          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
          });


          }
          });














          draft saved

          draft discarded


















          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









          1














          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')





          share|improve this answer






























            1














            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')





            share|improve this answer




























              1












              1








              1







              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')





              share|improve this answer















              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')






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Nov 23 '18 at 7:04

























              answered Nov 23 '18 at 6:53









              fa06fa06

              18k21018




              18k21018

























                  1














                  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')





                  share|improve this answer






























                    1














                    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')





                    share|improve this answer




























                      1












                      1








                      1







                      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')





                      share|improve this answer















                      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')






                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Nov 23 '18 at 7:09

























                      answered Nov 23 '18 at 6:53









                      Zaynul Abadin TuhinZaynul Abadin Tuhin

                      18.2k21134




                      18.2k21134























                          0














                          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'





                          share|improve this answer




























                            0














                            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'





                            share|improve this answer


























                              0












                              0








                              0







                              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'





                              share|improve this answer













                              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'






                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Nov 23 '18 at 6:52









                              forpasforpas

                              18.5k3728




                              18.5k3728























                                  0














                                  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')





                                  share|improve this answer




























                                    0














                                    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')





                                    share|improve this answer


























                                      0












                                      0








                                      0







                                      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')





                                      share|improve this answer













                                      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')






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Nov 23 '18 at 6:57









                                      kemal akoğlukemal akoğlu

                                      14911




                                      14911






























                                          draft saved

                                          draft discarded




















































                                          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.




                                          draft saved


                                          draft discarded














                                          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





















































                                          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







                                          這個網誌中的熱門文章

                                          Tangent Lines Diagram Along Smooth Curve

                                          Yusuf al-Mu'taman ibn Hud

                                          Zucchini