Tuesday, March 20, 2012

Pulling out table and column descriptions

When I run the following query:
Select * From Information_Schema.columns Where TABLE_NAME = 'Answers'
I see that, for my table "Answers", I have 9 rows returned, showing each
field in my table.
The sysobjects query shows where I can get the Id for Answers and use it for
getting the field descriptions from sysproperties (along with a table
description):
Select * From sysobjects Where name = 'Answers'
Select * From sysproperties Where id = 859150106
The trouble I am having is I want to join the the column and sysproperties
tables together, but I get back 38 rows showing a lot of duplicate data when
I only want the 9 rows that define my Answers table. Can someone show and
explain to me what I am doing wrong? Below is the query I tried that returne
d
38 rows instead of the 9 I wanted. Thank you.
Select isc.table_name, isc.column_name, sp.value
From sysproperties sp
Join Information_Schema.columns isc On sp.smallid = isc.ordinal_position
Where isc.table_name = 'Answers'Hello, Mike
Try something like this:
SELECT c.name as ColumnName, p.value as Description
FROM syscolumns c
INNER JOIN sysobjects o ON c.id=o.id
LEFT JOIN sysproperties p
ON p.smallid=c.colid AND p.id=o.id AND p.name='MS_Description'
WHERE o.name='YourTable' ORDER BY c.colid
Razvan|||Exactly what I wanted. Thanks.
"Razvan Socol" wrote:

> Hello, Mike
> Try something like this:
> SELECT c.name as ColumnName, p.value as Description
> FROM syscolumns c
> INNER JOIN sysobjects o ON c.id=o.id
> LEFT JOIN sysproperties p
> ON p.smallid=c.colid AND p.id=o.id AND p.name='MS_Description'
> WHERE o.name='YourTable' ORDER BY c.colid
> Razvan
>

No comments:

Post a Comment