March 28, 2007 at 7:36 am
information_schema views are the most correct way to do it;
IF EXISTS(select * from information_schema.columns where tablename='programversion' and columnname=@col )
BEGIN
SET @sql = 'ALTER TABLE [programversion] ADD [' + @col +'] varchar (200)'
exec (@sql)
END
this works too
select * from syscolumns where object_id(id) = '' and name=''
IF EXISTS(select * from syscolumns where object_id(id) = 'programversion' and name=@col )
BEGIN
SET @sql = 'ALTER TABLE [programversion] ADD [' + @col +'] varchar (200)'
exec (@sql)
END
Lowell
March 28, 2007 at 7:40 am
Didn't you mean
IF NOT EXISTS(select * from information_schema.columns where tablename='programversion' and columnname=@col )
Far away is close at hand in the images of elsewhere.
Anon.
March 28, 2007 at 7:40 am
many thanks Lowell, especially for the quick reply
March 28, 2007 at 7:44 am
That's true, but what's a 'NOT' between friends
March 28, 2007 at 7:45 am
Thanks David
March 28, 2007 at 7:55 am
I've just added your code to my Stored Procedure and when I do a Check syntax I get the following error message
invalid colomn name 'tablename'
invalid colomn name 'colomnname'
March 28, 2007 at 8:00 am
Mick
Books Online tells you the names of the columns. They're TABLE_NAME and COLUMN_NAME.
John
March 28, 2007 at 8:00 am
that's what i get for rushing out an answer;
David Burrows, as usual, is correct.
NOT Exists...
the fields are TABLE_NAME and COLUMN_NAMe...with underscores;
select * from information_schema.columns where table_name='' and column_name=''
Lowell
March 28, 2007 at 8:02 am
Thanks lads, it all works now thanks to you
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply