﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Article Discussions / Article Discussions by Author / Discuss content posted by kgayda  / Find Column Name Usage / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sat, 18 May 2013 10:14:14 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Find Column Name Usage</title><link>http://www.sqlservercentral.com/Forums/Topic405308-636-1.aspx</link><description>I found this very useful.  I am constantly looking for a particular element name.I took some liberties and enhanced my version of the code to look across all database on the server; using a cursor to store db names.My code enhancement is shown below.Arnie StewartDECLARE @DB AS VARCHAR(25)DECLARE @CNT AS INTDECLARE @SQL NVARCHAR(4000)DECLARE @vcColumnName varchar(100) ----SET @vcColumnName = 'PAT_NM'----DECLARE C1_CURSOR SCROLL CURSOR FOR SELECT  NAME AS DBFROM MASTER.dbo.sysdatabasesWHERE NAME NOT LIKE 'MASTER' ANDNAME NOT LIKE 'TEMPDB' ANDNAME NOT LIKE 'MODEL' ANDNAME NOT LIKE 'MSDB'ORDER BY NAMETRUNCATE TABLE ADHOC.DBO.TBL_IT_COLUMNS_DBASE_LOOKUPSET @CNT = 0OPEN C1_CURSORFETCH NEXTFROM C1_CURSORINTO  @DBWHILE @@FETCH_STATUS = 0   BEGIN		SET @SQL='INSERT INTO ADHOC.DBO.TBL_IT_COLUMNS_DBASE_LOOKUP					SELECT DISTINCT ''' + @DB + '''AS DBASE, SUBSTRING(o.NAME,1,60) AS [Table Name]					FROM ' +@DB+'.dbo.sysobjects o					INNER JOIN  ' +@DB+'.dbo.syscolumns c						ON o.ID = c.ID					WHERE c.name = ''' + @vcColumnName + '''						AND o.XTYPE = ''U''				ORDER BY  [Table Name]'		EXEC(@SQL)	      FETCH NEXT FROM C1_CURSOR INTO @DB   ENDCLOSE C1_CURSORDEALLOCATE C1_CURSORSELECT * FROM ADHOC.DBO.TBL_IT_COLUMNS_DBASE_LOOKUP</description><pubDate>Mon, 22 Oct 2007 10:01:53 GMT</pubDate><dc:creator>Arnie Stewart</dc:creator></item><item><title>RE: Find Column Name Usage</title><link>http://www.sqlservercentral.com/Forums/Topic405308-636-1.aspx</link><description>Thanks for the tip!</description><pubDate>Wed, 10 Oct 2007 13:25:19 GMT</pubDate><dc:creator>kgayda</dc:creator></item><item><title>RE: Find Column Name Usage</title><link>http://www.sqlservercentral.com/Forums/Topic405308-636-1.aspx</link><description>Try this for a trick: use Excel/MS Query to open INFORMATION_SCHEMA.COLUMNS then use Autofilter to create a simple data dictionary tool that does something very similar to your script.</description><pubDate>Mon, 08 Oct 2007 09:05:35 GMT</pubDate><dc:creator>Andrew_Webster</dc:creator></item><item><title>Find Column Name Usage</title><link>http://www.sqlservercentral.com/Forums/Topic405308-636-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/scripts/Miscellaneous/31964/"&gt;Find Column Name Usage&lt;/A&gt;[/B]</description><pubDate>Mon, 01 Oct 2007 16:32:13 GMT</pubDate><dc:creator>kgayda</dc:creator></item></channel></rss>