ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

need a favor, where clause with multiple value

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • need a favor, where clause with multiple value

    Have a good day for everyone !

    Does anyone help for where clause with multiple value ,
    I am try for case when in where clause but it doesn't work.
    it could be write in another way in sql/400 ?

    Here is my example statement .
    SELECT item , code_product , location, datesale
    FROM mylib/product
    WHERE case when moth(current timestamp)=04 and then datesale between 20180101 and 20180331 else datesale between 20180401 and 20180630 end

    would appreciated any advice . Thank you so much ​​​​​​​

    tintin

  • #2
    I'm not quite sure what you need ... If we are in april (month(Current_Timestamp) = 4) you want to have a date range for the first quarter in 2018 (20180101 - 20180331) otherwise the date range of the second quarter 2018 (2018401 - 201800630) ?
    If so try the following:
    Code:
    SELECT item , code_product , location, datesale
       FROM mylib/product
       WHERE DateSale Between case when month(current_timestamp) = 4
                                   Then 20180101
                                   Else 20180401 End
                          and case When Month(Current_Timestamp) = 4          
                                   Then 20180331
                                   else 20180630 end
    Birgitta

    Comment


    • #3
      I'm not sure what you're trying to accomplish. Would something like this get you what you need?
      Code:
      SELECT item , code_product , location, datesale
      FROM mylib/product
      WHERE (month(current_timestamp)=04 and datesale between 20180101 and 20180331)
           or (month(current_timestamp) <> 04 and datesale between 20180401 and 20180630)

      Comment

      Working...
      X