cancel
Showing results for 
Search instead for 
Did you mean: 

Question about if expression

Former Member
3,106

I'm trying to create an IF statement but I can't get it to work in SQL Anywhere 9. Here is the SQL:

 select
        MICROS.time_card_dtl.emp_seq,
        MICROS.time_card_dtl.clk_in_date_tm,
        MICROS.time_card_dtl.clk_out_date_tm,
        MICROS.time_card_dtl.reg_hrs,
        MICROS.time_card_dtl.job_seq,
        jd.name,
        if hour(MICROS.time_card_dtl.clk_in_date_tm) < 5 then
              dateadd(day, -1, (date(MICROS.time_card_dtl.clk_in_date_tm)))
        else
              date(MICROS.time_card_dtl.clk_in_date_tm)
        end if

  from
        MICROS.time_card_dtl
  inner join
        micros.job_def jd on jd.job_seq = MICROS.time_card_dtl.job_seq
  where
        MICROS.time_card_dtl.clk_in_date_tm between '2013-05-10 00:07:00' and '2013-05-13 04:00:00'
  group by
        MICROS.time_card_dtl.emp_seq, MICROS.time_card_dtl.clk_in_date_tm, MICROS.time_card_dtl.clk_out_date_tm, MICROS.time_card_dtl.reg_hrs, MICROS.time_card_dtl.job_seq, jd.name
  order by
        MICROS.time_card_dtl.emp_seq

I don’t know SQL Anywhere very well, but I am very familiar with MySQL. We don’t have the SQL Anywhere 9 manual, and I’ve been trying to get by with the SQL Anywhere 10 manual found here:

http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.help.ase_15.0.blocks/html/blocks/block...

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member

Apparently you have to use:

endif

instead of:

end if

VolkerBarth
Contributor

Yes, that's true for the IF expression in v10 and below. Note that the IF statement is ended with END IF, in contrast.

v11 introduced the nice addition that you can use both ENDIF or END IF both for IF expressions and IF statements - cf. this doc page on v11:

SQL Anywhere 11 - Changes and Upgrading - What's new in version 11.0.0 - SQL Anywhere » SQL Anywhere...

BTW: DCX is a handy site to access current SQL Anywhere documentation...

Breck_Carter
Participant

Raphael, if you send me an email at breck dot carter@gmail.com I will send you the Help files for V9.

Plus, you can buy my book, it's on V9.