?
Solved

printing variable values in DB2

Posted on 2014-01-23
5
Medium Priority
?
5,918 Views
Last Modified: 2014-01-31
Hi Experts,  I've got the following code in MS-SQL-Server
 
DECLARE @TotAcct  VARCHAR(20)
SET @TotAcct =  (   SELECT COUNT(*) FROM ACCOUNT a )
PRINT 'Total Account:      ' + @TotAcct

Open in new window

Which works fine but I'm migrating it to DB2.  I have the following:
CREATE VARIABLE TotAcct  INTEGER;
SET TotAcct = (   SELECT COUNT(*) FROM ACCOUNT a);
DISPLAY 'Total Account:      ' + TotAcct;
DROP VARIABLE TotAcct;

Open in new window


Trouble is I cannot figure out how to print the output as I've done in SQLServer.

I'm probably just missing something.  Does anyone have any ides?
0
Comment
Question by:MikeDelaney
  • 2
  • 2
5 Comments
 
LVL 18

Expert Comment

by:Dave Ford
ID: 39804217
Which "flavor" of DB2 are you using? (mainframe, Unix, Linux, AS/400, etc)
0
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 39804219
Hi Mike,

DB2 is a lot different than SQL Server.  SQL Server is mostly a unified environment where the development environment (client) and the database server are tightly coupled.  The DB2 server is 100% independent of the development environment (except for them being compatible, of course).

As such, DB2 does not have a PRINT statement.  There are several free development environments available for DB2.  You could use the Store Procedure Editor and step through it to see the variables, or save the values to a debug table and inspect them later.  But PRINT to the output file just won't work.


Kent
0
 

Author Comment

by:MikeDelaney
ID: 39804474
I'm calling the script from the DB2CMD (which is connecting to DB2-9.2)  That being the case, I might be able to insert the lines into a temp DB and simply 'SELECT * FROM TMP;'  It's a pity that I can't actually display the contents of a variable though - that would have been ideal.


Thanks, Mike
0
 
LVL 46

Accepted Solution

by:
Kent Olsen earned 2000 total points
ID: 39804726
If you're running the SQL as a script, you can always just SELECT xxx in the script and let the result get written to the output file.  That must be done from the script SQL though as that syntax of the SELECT statement won't work in a stored procedure.


Kent
0
 

Author Closing Comment

by:MikeDelaney
ID: 39824473
That worked in the end.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

November 2009 Recently, a question came up in the DB2 forum regarding the date format in DB2 UDB for AS/400.  Apparently in UDB LUW (Linux/Unix/Windows), the date format is a system-wide setting, and is not controlled at the session level.  I'm n…
Recursive SQL in UDB/LUW (you can use 'recursive' and 'SQL' in the same sentence) A growing number of database queries lend themselves to recursive solutions.  It's not always easy to spot when recursion is called for, especially for people una…
Loops Section Overview
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question