title: Referenced Entities in a Stored Procedure
body: <p>Trying to get the objects referenced within stored procedure dynamically. Below code doesn't work when it's dynamic</p>
  
  <pre><code>DECLARE @procname VARCHAR(50) = 'GetTempBondInformation'
  SELECT  QUOTENAME('dbo.' + @procname ,'''')
  SELECT  DISTINCT referenced_entity_name  FROM    sys.dm_sql_referenced_entities(QUOTENAME('dbo.' + @procname ,''''), 'OBJECT')
  </code></pre>
  
  <p>Whereas below code works fine.</p>
  
  <pre><code>SELECT  DISTINCT referenced_entity_name  FROM    sys.dm_sql_referenced_entities('dbo.GetTempBondInformation', 'OBJECT')
  </code></pre>
  
  <p>Any clues?</p>