Hi,

I have error when running the following script:

IF (select rest_name from table.rest_def) <> 'TESTING' THEN
    RETURN
  ELSE
    SELECT net_sls_ttl 
    FROM table.dly_sys_ttl
    WHERE cast((getDate()) As Date) = cast(dly_sys_ttl.business_date As Date);

    OUTPUT TO D:\TimeCard.csv
    FORMAT TEXT;

END IF

The error is

"Could not execute statement. Syntax error near 'OUTPUT' on line 8. SQLCODE=-131. ODBC 3 STATE="42000" Line 1 column 5"

However, there is no error if I remove the IF statement. The text file can be exported if I only run these:

SELECT net_sls_ttl 
FROM table.dly_sys_ttl
WHERE cast((getDate()) As Date) = cast(dly_sys_ttl.business_date As Date);

OUTPUT TO D:\TimeCard.csv
FORMAT TEXT;

Please help :(

asked 12 Dec '13, 05:37

ctlavender's gravatar image

ctlavender
1094410
accept rate: 0%


OUTPUT is an ISQL command, not a SQL statement, and as such, cannot be used within procedures and code blocks - and the IF statement makes your list of statements a code block. (In contrast, your list of statements without the IF statement is not a code block, i.e. each statement is sent to the database engine each on its own (here's only one: the SELECT statement), and then DBISQL processes the OUTPUT command itself.)

Therefore you need to use the UNLOAD statement instead of OUTPUT - cf. this related question:

permanent link

answered 12 Dec '13, 06:12

Volker%20Barth's gravatar image

Volker Barth
30.8k308456665
accept rate: 32%

edited 12 Dec '13, 09:17

Mark%20Culp's gravatar image

Mark Culp
23.2k9132272

Oh my god it works!! Thank you so much for helping out. Appreciate it. :D

(12 Dec '13, 21:04) ctlavender
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:

×25
×8

question asked: 12 Dec '13, 05:37

question was seen: 780 times

last updated: 12 Dec '13, 21:04