Hi Experts,
I am having a problem with the CASE condition in the WHERE clause of my SELECT statement. (Sample code below).
The following select is used in a stored procedure which takes in a couple strings. If the string is NULL, the MakeTempTable function for the corresponding table is not invoked, hence the temp table is not created.
I am trying to condition whether or not to use the IN (Select...) in WHERE based on if the string is NULL or not.
However, the Or part of the condition seems to be invoked regardless. I have tried replacing WHEN NULL is NULL with WHEN 'a' = 'a' and the Or is still invoked.
I am new to mySQL so I suspect the structure of condition is wrong and may not be related to CASE statement at all.
Working with Workbench, the following line is throwing the error:
(1=(CASE WHEN NULL is NULL THEN 1 ELSE 0 END) Or pae.pitcherid IN (Select id from temppid100))
Error Code: 1146 Table 'gamedatareport.temppid100' doesn't exist
Here is the sample code. I've hardcoded for the parameters.
/*string for temppid is NULL, so temppid100 is not created*/
/*This line creates tempHid100 used below.*/
Call MakeTempTable ('100','31982,15562,20712',0);
      SELECT Â
           pae.PitchAndEventId,
           gh.`Date` AS Date           Â
   Â
      FROM  Â
           GameDataReport.gameheader gh
           INNER JOIN pitchandevent pae ON pae.gameid = gh.gameid
   Â
      WHERE
           gh.Date >= '2016-08-01' AND
        gh.Date <= '2016-09-18' AND
           (1=(CASE WHEN '31982,15562,20712' IS NULL THEN 1 ELSE 0 END) Or pae.hitterid IN (Select id from temphid100)) AND
        /*This is the line erroring*/
           (1=(CASE WHEN NULL is NULL THEN 1 ELSE 0 END) Or pae.pitcherid IN (Select id from temppid100))
    Order by pae.gameid,pae.recordsequence;
   Â
call droptemptable ('temppid100');
call droptemptable ('temphid100');
can you make sure you got a table: temppid100 in schema: gamedatareport ?
is this question for MySQL or MS SQL ?