|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Monday, May 20, 2013 6:47 AM
Points: 581,
Visits: 694
|
|
| Great question! Learned something new. Thanks.
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Monday, May 06, 2013 6:51 AM
Points: 989,
Visits: 1,790
|
|
| It is correct to say that removing the GO between the EXEC call and the SELECT against the DMV changes the behavior. Clearly there is some caching going on at least for the duration of the batch itself, and removing it from cache when the batch completes.
|
|
|
|
|
SSChasing Mays
      
Group: General Forum Members
Last Login: Thursday, February 21, 2013 5:19 PM
Points: 658,
Visits: 455
|
|
| Learned something new from the discussion. Thanks guys.
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Yesterday @ 12:55 PM
Points: 2,015,
Visits: 2,847
|
|
| The distribution of answers is almost even. That shows that this was a real brain tickler.
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: 2 days ago @ 10:53 AM
Points: 1,662,
Visits: 1,709
|
|
Carlo Romagnano (11/14/2010) In sql2005, I get an error: "plan_handle" is not a recognized table hints option.
Carlo,
Please check compat level of your SQL Server 2005 AdventureWorks database. If the level is 80 then you should get "plan_handle" is not a recognized table hints option error, but if it is 90 as it should be then the script should run just fine.
Oleg
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Yesterday @ 1:51 AM
Points: 1,972,
Visits: 1,821
|
|
Oleg Netchaev (11/15/2010)
Carlo Romagnano (11/14/2010) In sql2005, I get an error: "plan_handle" is not a recognized table hints option.
Carlo, Please check compat level of your SQL Server 2005 AdventureWorks database. If the level is 80 then you should get "plan_handle" is not a recognized table hints option error, but if it is 90 as it should be then the script should run just fine. Oleg I tried at midnight, maybe, my notebook or I was out of order.  Thank you
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Tuesday, January 15, 2013 10:46 AM
Points: 911,
Visits: 831
|
|
Using the code supplied, I got this result:
-- uspPrintError prints error information about the error that caused -- execution to jump to the CATCH block of a TRY...CATCH construct. -- Should be executed from within the scope of a CATCH block otherwise -- it will return without printing any error information. CREATE PROCEDURE [dbo].[uspPrintError] AS BEGIN SET NOCOUNT ON; -- Print error information. PRINT 'Error ' + CONVERT(varchar(50), ERROR_NUMBER()) + ', Severity ' + CONVERT(varchar(5), ERROR_SEVERITY()) + ', State ' + CONVERT(varchar(5), ERROR_STATE()) + ', Procedure ' + ISNULL(ERROR_PROCEDURE(), '-') + ', Line ' + CONVERT(varchar(5), ERROR_LINE()); PRINT ERROR_MESSAGE(); END; SELECT st.text QueryText FROM sys.dm_exec_cached_plans CROSS APPLY sys.dm_exec_sql_text(plan_handle) AS st WHERE text LIKE N'%uspPrintError%';
The only way to get the "correct" answer the author intended is to remove the "GO statement between EXEC uspPrintError and the SELECT stmt.
I'm using SQL 2005, compat. level 90.
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Monday, May 06, 2013 6:51 AM
Points: 989,
Visits: 1,790
|
|
mojo-168709 (11/15/2010)
Using the code supplied, I got this result: -- uspPrintError prints error information about the error that caused -- execution to jump to the CATCH block of a TRY...CATCH construct. -- Should be executed from within the scope of a CATCH block otherwise -- it will return without printing any error information. CREATE PROCEDURE [dbo].[uspPrintError] AS BEGIN SET NOCOUNT ON; -- Print error information. PRINT 'Error ' + CONVERT(varchar(50), ERROR_NUMBER()) + ', Severity ' + CONVERT(varchar(5), ERROR_SEVERITY()) + ', State ' + CONVERT(varchar(5), ERROR_STATE()) + ', Procedure ' + ISNULL(ERROR_PROCEDURE(), '-') + ', Line ' + CONVERT(varchar(5), ERROR_LINE()); PRINT ERROR_MESSAGE(); END; SELECT st.text QueryText FROM sys.dm_exec_cached_plans CROSS APPLY sys.dm_exec_sql_text(plan_handle) AS st WHERE text LIKE N'%uspPrintError%';
The only way to get the "correct" answer the author intended is to remove the "GO statement between EXEC uspPrintError and the SELECT stmt. I'm using SQL 2005, compat. level 90.
I am confused -- the code you posted IS the expected result? CREATE instead of EXEC?
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Monday, May 13, 2013 11:21 AM
Points: 2,163,
Visits: 2,148
|
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: 2 days ago @ 12:03 PM
Points: 412,
Visits: 862
|
|
EXEC uspPrintError GO
I know before this thing but I answered it wrong bcoz
EXEC uspPrintError GO
what this doing over there.
--SQLFRNDZ
|
|
|
|