What am I Doing?

Monday, July 23, 2007

Intra Entry: SQL Script

Dear Diary,

File As: "Help Desk"

Here's a small SQL script I wrote to help me find a field name.  I was looking for a field called "cash out amount," but I did not want to go searching through 50 different tables containing 300+ fields.  The script below did that for me.

All I had to do was type a small piece of the word ("cash") and POOF!  The script returned a list of all the tables with the word "cash" in a field name.

SELECT CONVERT(VARCHAR(35), t.name) 'Table Name', CONVERT(VARCHAR(35), c.name) 'Column Name'
FROM [DB NAME]..syscolumns c
JOIN [DB NAME]..sysobjects t
ON c.id = t.id
WHERE c.name like '%cash%'

P.S. Don't forget to change "[DB NAME]" to the name of the database you're using.

Tags: intra entry, sql, help desk

No comments: