Thread: Stored proc with dynSQL issue
06-28-14, 22:38 #1Registered User
- Join Date
- Feb 2004
- Bangalore, India
Unanswered: Stored proc with dynSQL issue
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?
Declare @sql NVARCHAR(MAX) =''
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)
06-30-14, 14:32 #2Annie's Dog Walker
Provided Answers: 6Loop1
- Join Date
- Nov 2004
- on the wrong server
Barring that, have you looked at the execution plan and the table level I/O?If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry. Earnest Hemingway, A Farewell To Arms.