?
Solved

debug stored procedure

Posted on 2003-03-12
5
Medium Priority
?
235 Views
Last Modified: 2006-11-17
Can you debug a stored procedure using SQL Server 7? If so, how. I don't see a debug feature on any menus but I thought I heard somewhere that you can.
0
Comment
Question by:stacey14
[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
  • 3
5 Comments
 
LVL 3

Accepted Solution

by:
chickenfrank earned 150 total points
ID: 8121713
Add print or select statements to your stored procedure and execute the stored procedure from query analyzer.

for example:  
print @variable

OR  
select @variable AS 'value of @variable after the insert'


For me, this is the easiest way to debug.  Not very elegant, but it doesn't require installing anything.  Its perhaps a little more tedious.  Even if you use a debugginf utility, you still have to set up breakpoints, which also requires work.

If you're debugging an application, you can run sql profiler to capture how the stored procedure is being called by the application.  copy and paste into query analyzer and hit run.  look for what your print statements print out.
0
 
LVL 1

Expert Comment

by:Aycex
ID: 8122472
Depends on exactly what you are looking for.  I know some people like to know exactly where or at least narrow it down to a couple of lines.  In that case use




Selsct *

select 10

FROM table_1

select 20


WHERE product_id = 2342346864

Select 30
0
 
LVL 1

Expert Comment

by:Aycex
ID: 8122535
Depends on exactly what you are looking for.  I know some people like to know exactly where or at least narrow it down to a couple of lines.  In that case use




Selsct *

select 10

FROM table_1

select 20


WHERE product_id = 2342346864

Select 30
0
 
LVL 4

Expert Comment

by:JohnChapin
ID: 8122624
This problem drove me crazy until i gave up and created a debug table. I use this code and repeat inserts as necessary.  
a_JCC_rc is a four column table
prime-key
varchar
date
int





DECLARE  @retrows int
DECLARE  @DEBUGLOG int
DECLARE @TimeStamp datetime
set @TimeStamp = getdate()                 -- now
--set @DEBUGLOG = 0               -- for production
set @DEBUGLOG = 1               -- for test

set nocount on --To allow only last select to return rows from execution, using a cursor kills this attempt


if (@DEBUGLOG = 1) Truncate table  a_JCC_rc     --reset counters for new test
set @retrows = @@rowcount
if (@DEBUGLOG = 1) insert into a_JCC_rc  values ('----------db ' + @DataBaseName, getdate(), @retrows )

-- Select statement in development

set @retrows = @@rowcount
if (@DEBUGLOG = 1) insert into a_JCC_rc  values ('1- Select identifier ', @TimeStamp, @retrows )
if (@DEBUGLOG = 1) insert into a_JCC_rc  (Returned_rows_label)    select distinct UserLogin from #temp


select * from a_jcc_rc
0
 
LVL 1

Expert Comment

by:Aycex
ID: 8122747
Depends on exactly what you are looking for.  I know some people like to know exactly where or at least narrow it down to a couple of lines.  In that case use




Selsct *

select 10

FROM table_1

select 20


WHERE product_id = 2342346864

Select 30
0

Featured Post

What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Suggested Courses

770 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