Solved

printing variable values in DB2

Posted on 2014-01-23
5
4,183 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:Kdo
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:
Kdo 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Recursive SQL in UDB/LUW (it really isn't that hard to do) Recursive SQL is most often used to convert columns to rows or rows to columns.  A previous article described the process of converting rows to columns.  This article will build off of th…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now