Solved

How to use Print statement  in Store procedure

Posted on 2007-11-25
5
175 Views
Last Modified: 2010-04-21
I have a store procedure with a Print Statement,

ALTER Procedure [dbo].[sp_ProcessImage]
      @Err int OUTPUT
      
As
declare @rowPro integer      -- 1 row must be Updated
                                                
select @Err = 1      
Begin Tran

INSERT INTO Asset
( .....

select @rowPro = @@rowcount
      
if @rowPro <> 1 or @@error != 0
      begin
            Rollback Tran
            select @Err = 1
            return
      end
Commit Tran
      select @Err = 0      
      return

print 'Rowpro=' + @rowPro


After I run procedure I hope I can get 'Rowpro=1', but I didn't get anyting print out. How I can trace the value of a variable inside procedure?  
0
Comment
Question by:dshi15
[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 75

Expert Comment

by:Aneesh Retnakaran
ID: 20346325
put the print statement before the 'return statement'


Commit Tran
      select @Err = 0      
 
print 'Rowpro=' + @rowPro

    return
0
 
LVL 1

Author Comment

by:dshi15
ID: 20346358
Hi,
I forgot how to convert int.

print 'Rowpro=' + convert(@rowPro,varchar(25)) is not work. thanks.
0
 
LVL 35

Assisted Solution

by:David Todd
David Todd earned 100 total points
ID: 20347750
Hi,

Your convert is back-to-front

print 'Rowpro = ' + convert( varchar( 25 ), @testInt )

and dont forget to put it _before_ the return!

Cheers
  David
0
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 150 total points
ID: 20347818
print 'Rowpro=' + cast (@rowPro  as varchar(25))
0
 
LVL 1

Author Closing Comment

by:dshi15
ID: 31410866
thanks
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

630 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