larsbloch
5/29/2018 - 10:49 AM

sql column search

DECLARE @SearchColumnName nvarchar(255) DECLARE @SearchColumnType nvarchar(255) DECLARE @SearchTableName nvarchar(255)
 
-----------------------------Search values--------------------------------------------
 
SET @SearchColumnName ='%propertynumber%' 
SET @SearchColumnType = '%%'
SET @SearchTableName = '%%'
 
------------------------------The Code-------------------------------------------
 
SELECT      t.name AS 'TableName', 
			c.name  AS 'ColumnName',
            y.name as 'DataType'
FROM        sys.columns c
JOIN        sys.tables  t ON c.object_id = t.object_id
JOIN		sys.types y ON y.user_type_id = c.user_type_id
WHERE       c.name LIKE @SearchColumnName
		AND y.name LIKE @SearchColumnType
		AND t.name LIKE @SearchTableName
ORDER BY    TableName ,ColumnName;