Home Forums SQL Server 2005 T-SQL (SS2K5) stored procedure---finding all tables that contain a specific column RE: stored procedure---finding all tables that contain a specific column

  • --The procedure was created ok:

    CREATE PROC sp_WhichTable

    @ColumnName varchar(50)

    AS

    SELECT o.name as [Table], c.name as [Column]

    FROM SYSOBJECTS o JOIN SYSCOLUMNS c ON o.id = c.id

    WHERE c.name like '%order%' AND o.xtype = 'u'

    ORDER BY 1

    --When I execute the sp :

    exec sp_WhichTable @ColumnName = 'invoiceID'

    I get 2 blank columns with the column headers TABLE and COLUMN. I expected to get some results.

    Looking at the tables I see that the column InvoiceID is in the InvoicesTable and InvoicesLineItems Tables.