[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

printing variable values in DB2

Posted on 2014-01-23
5
Medium Priority
?
5,613 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 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

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 video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

649 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