Solved

printing variable values in DB2

Posted on 2014-01-23
5
5,024 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

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 (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…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

705 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