Solved

printing variable values in DB2

Posted on 2014-01-23
5
4,603 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:daveslash
ID: 39804217
Which "flavor" of DB2 are you using? (mainframe, Unix, Linux, AS/400, etc)
0
 
LVL 45

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 45

Accepted Solution

by:
Kent Olsen earned 500 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

856 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