Declare variables in sql statement

Ask question on - DataBase Concepts, IBM Mainframe DB2, DB2/UDB, DB2 Tools, SQL , DB2 programming with languages like COBOL, PL1.

Moderators: Kalicharan, Moderator Group

Post Reply
xgenius
Member
Posts: 3
Joined: Mon Jul 06, 2009 7:49 pm

Declare variables in sql statement

Post by xgenius » Mon Jul 06, 2009 8:16 pm

Hello,

I execute some sql request from SPUFI utility, and I need to declare variable but it return me sql error

Code: Select all

Request:
DECLARE H_D_FIN_6MOIS DATE;                                             

Result:
---------+---------+---------+---------+---------+---------+---------+-------
DSNT408I SQLCODE = -104, ERROR:  ILLEGAL SYMBOL "DATE". SOME SYMBOLS THAT
         MIGHT BE LEGAL ARE: TABLE STATEMENT , . SCROLL INSENSITIVE SENSITIVE
         ASENSITIVE NO
[/code]

User avatar
Natarajan
Moderator
Posts: 537
Joined: Fri Oct 10, 2008 12:57 pm
Location: chennai
Contact:

Post by Natarajan » Tue Jul 07, 2009 10:27 am

Try using SET command.

Code: Select all

SET H_D_FIN_6MOIS = DATE;
Natarajan
Chennai

xgenius
Member
Posts: 3
Joined: Mon Jul 06, 2009 7:49 pm

Post by xgenius » Tue Jul 07, 2009 12:55 pm

thanks for the answer;

but it doesn't work too, it seems to be for host variable assignement. I think declaring variable is only for stored procedures isn't it?

Code: Select all

SET H_D_FIN_6MOIS = DATE;                                               00000
---------+---------+---------+---------+---------+---------+---------+-------
DSNT408I SQLCODE = -104, ERROR:  ILLEGAL SYMBOL "H_D_FIN_6MOIS". SOME SYMBOLS
         THAT MIGHT BE LEGAL ARE: :

User avatar
dbzTHEdinosauer
Moderator
Posts: 981
Joined: Mon Oct 02, 2006 8:31 pm

Post by dbzTHEdinosauer » Tue Jul 07, 2009 1:25 pm

I think declaring variable is only for stored procedures isn't it?
Start looking in the manuals for answers instead of incorrectly guessing.
explanation of DECLARE VARIABLE
Dick Brenholtz
JCL, SQL and code in programs have an irritating habit of doing what you say,
not what you meant.

xgenius
Member
Posts: 3
Joined: Mon Jul 06, 2009 7:49 pm

Post by xgenius » Tue Jul 07, 2009 6:45 pm

I'm not guessing, I read the documentation before but when I try the example, I got error.
In the DB2 manual they show declaring variable for stored procedure only.
This is the link where i read from http://publib.boulder.ibm.com/infocente ... lsqlpl.htm

User avatar
dbzTHEdinosauer
Moderator
Posts: 981
Joined: Mon Oct 02, 2006 8:31 pm

Post by dbzTHEdinosauer » Tue Jul 07, 2009 7:04 pm

You seem to stop looking when you thinkyou have an answer. You would be better off researching in the correct area, instead drawing an incorrect conclusion by looking at something else - COMPOUND STATEMENT.
This is the DB2 Vsn 9 explanation of DECLARE VARIABLE

This is Vsn 8

You were not thinking - or possibly, you just don't know very much about DB2 terms
(e.g. application program) - basic fundamentals, which leads you to incorrect conclusions, and then trying to defend them makes you look even sillier:

and
xxgenius wrote:I execute some sql request from SPUFI utility, and I need to declare variable but it return me sql error
SPUFI is not using the Statement in an application program.

spend more time learning instead of defending the indefensible - i.e. your error.
Dick Brenholtz
JCL, SQL and code in programs have an irritating habit of doing what you say,
not what you meant.

Post Reply

FREE TUTORIALS

Tutorials
Free tutorials from mainframegurukul
  • JCL Tutorial
    Covers all important JCL concepts.
  • Cobol Tutorial
    This tutorials covers all Cobol Topics from STRING to COMP-3.
  • DB2 Tutorial
    DB2 Tutorial focuses on DB2 COBOL Programming.
  • SORT Tutorial
    This Tutorial covers all important aspects of DFSORT with examples
  • CICS Tutorial
    This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions



Other References
Mainframe Tools and others