Tuesday, June 7, 2011

Find all stored procedures where a column is being used/referenced

-- compliments from SQLUSA

   1:  USE AdventureWorks2008; 
   2:  DECLARE @SchemaName sysname = N'Production'; 
   3:  DECLARE @TableName sysname = N'Product'; 
   4:  DECLARE @ColumnName sysname = N'ProductID'; 
   5:  SELECT QUOTENAME(refing.referencing_schema_name) + 
   6:  N'.' + QUOTENAME(refing.referencing_entity_name) As SprocName 
   7:  FROM sys.dm_sql_referencing_entities(QUOTENAME(ISNULL(@SchemaName,N'dbo')) + 
   8:  N'.' + QUOTENAME(@TableName),'object') refing 
   9:  CROSS APPLY sys.dm_sql_referenced_entities(QUOTENAME(refing.referencing_schema_name) + 
  10:  N'.' + QUOTENAME(refing.referencing_entity_name), 'object') refed 
  11:  WHERE EXISTS(SELECT * FROM sys.objects 
  12:  WHERE refing.referencing_id = object_id and type ='P') 
  13:  AND refed.referenced_schema_name = @SchemaName 
  14:  AND refed.referenced_entity_name = @TableName 
  15:  AND refed.referenced_minor_name  = @ColumnName 
  16:  ORDER BY SprocName;
  17:   

DATETIME in Store Procedure and Date/Time in Reporting Service

In SP, if you specify only YYYYMMDD and no timestamp, the default one is 0000000. However, in Reporting service parameter section, if the datatype is Date/Time and no time stamp specified, the default one is 125959am. (to be confirmed?)