April 30, 2004 at 1:46 pm
How can I check to see if a column exists in a table by using
the MS system store procedures?
April 30, 2004 at 2:37 pm
With many, sp_help, sp_columns, etc.
You can also use a query like this:
IF EXISTS (SELECT 1 FROM syscolumns where name = 'ColName' AND OBJECT_NAME(id) = 'TableName') PRINT 'Exists' ELSE PRINT 'no exists'
May 3, 2004 at 2:53 pm
Thanks for the reply. I have another question:
If I use the following:
EXEC sp_columns @table_name = 'X', @column_name = 'YY'
How do I check if the result set returned is empty or not.
May 3, 2004 at 3:05 pm
After the execution of the procedure, you can check @@ROWCOUNT
EXEC sp_columns @table_name='X', @column_name='YY'
IF @@ROWCOUNT>0
BEGIN
Insert code here
END
Brian
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply