Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

Stored proc with dynSQL issue

$
0
0
Hello All:

I am facing a prob in one of my stored procedures. The proc executes some dynamic sql and it never completes.

Initially i thought it was a performance issue with the "INSERT INTO ..SELECT..." query which cause this delay, but the query completes in 2-3 seconds if executed from Sql Management studio.

I ran SQL profiler trace for this stored proc and it is shows "Stmt starting EXEC (@sql)" statement and nothing beyond that. At this time, i noticed that no other SPIDs are blocking this proc and the server CPU/memory usage does not show any significant variation..

The pseudo-code is given below.

Any thoughts on why this is happening?

stored proc
...
Declare @sql NVARCHAR(MAX) =''
@id int
....
Loop1
....
Loop2
....
Loop3
.....
SET @sql = 'insert into #results select distinct x,y,z from view v join tablename t on t.x=v.x where t.id= '+ convert(nvarchar(10),@id)
print @sql
EXEC (@sql)
End Loop3
.....
End Loop2
....
End Loop1

Thanks,
Baburaj

Viewing all articles
Browse latest Browse all 13329

Trending Articles