Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Update Column if exists.

Author  Topic 

samsekar
Constraint Violating Yak Guru

437 Posts

Posted - 2004-07-28 : 09:23:26
Hi I am trying to update the column if that column exists in the table. This table is generated dynamically. I have wrote stored procedure something like this, but it gives Invalid column name at runtime. Any help is highly appreciated !!

IF EXISTS (Select * from syscolumns where [name] = 'tag' and [id] = object_id('tableA'))
BEGIN
UPDATE A SET A.tag = B.tag
FROM tableA A JOIN tableB B ON A.id = B.id
END


- Sekar

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2004-07-28 : 09:40:04
??? Why would you even try to do this?

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page

samsekar
Constraint Violating Yak Guru

437 Posts

Posted - 2004-07-28 : 09:44:58
The table is generated dynamically, the generated table might have the column based on the input given for table creation. In the stored procedure, if the column exists i need to update the data. Can someone throw some lights on this

Infact I am trying to do without using Dynamic SQL
- Sekar
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2004-07-28 : 10:03:40
Have SProc_A and SProc_B - one which does the extra column, and one which doesn't - and EXEC which ever is appropriate??

Kristen
Go to Top of Page

samsekar
Constraint Violating Yak Guru

437 Posts

Posted - 2004-07-28 : 10:08:46
Thanks Kristen, Even I thought the same, infact there are some 5-6 columns which gets updated from different tables. And I dont want to have 6-7 stored procedures, any other thoughts!!.

- Sekar
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2004-07-28 : 10:11:47
What are these columns for? User Defined fields, or something like that?

Kristen
Go to Top of Page
   

- Advertisement -