Please be aware that the content in SAP SQL Anywhere Forum will be migrated to the SAP Community in June and this forum will be retired.

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/blocks121.htm

asked 16 May '13, 09:57

raphael's gravatar image

raphael
1515614
accept rate: 33%

edited 16 May '13, 11:01

Mark%20Culp's gravatar image

Mark Culp
24.9k10141297

1

Note: What you name an IF statement, is really an IF expression - as it is simply a part of a SELECT statement.

(16 May '13, 10:43) Volker Barth

Apparently you have to use:

endif

instead of:

end if

permanent link

answered 16 May '13, 10:03

raphael's gravatar image

raphael
1515614
accept rate: 33%

2

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 new features - SQL statements

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

(16 May '13, 10:40) Volker Barth

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.

permanent link

answered 16 May '13, 15:00

Breck%20Carter's gravatar image

Breck Carter
32.5k5417261050
accept rate: 20%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×108
×5

question asked: 16 May '13, 09:57

question was seen: 2,756 times

last updated: 16 May '13, 15:00