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 2005 Forums
 Transact-SQL (2005)
 adding a condition

Author  Topic 

rajasekhar857
Constraint Violating Yak Guru

396 Posts

Posted - 2009-09-01 : 05:31:21
Hi,how to add a condition

ALTER TABLE EmrLicenseInfo ADD LICENSE_GROUP VARCHAR(100) default null

ALTER TABLE EmrLicenseInfo ADD PRODUCT_VERSION VARCHAR(200) default null


Note: Add a condition that if column is not there then add column

matty
Posting Yak Master

161 Posts

Posted - 2009-09-01 : 05:36:09
IF NOT EXISTS(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='EmrLicenseInfo' and COLUMN_NAME = 'LICENSE_GROUP')
ALTER TABLE EmrLicenseInfo ADD LICENSE_GROUP VARCHAR(100) default null
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-09-01 : 05:36:29
if not exists (select * from sys.columns where
name ='LICENSE_GROUP' and object_id= object_id('EmrLicenseInfo'))
begin

ALTER TABLE EmrLicenseInfo ADD LICENSE_GROUP VARCHAR(100) default null

End

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-09-01 : 05:36:53
if not exists(select * from information_schema.columns where table_name = 'EmrLicenseInfo' and column_name = 'LICENSE_GROUP' )
ALTER TABLE EmrLicenseInfo ADD LICENSE_GROUP VARCHAR(100) default null
Go to Top of Page

rajasekhar857
Constraint Violating Yak Guru

396 Posts

Posted - 2009-09-01 : 05:44:57
Thank you
Go to Top of Page

rajasekhar857
Constraint Violating Yak Guru

396 Posts

Posted - 2009-09-01 : 06:34:06
in oracle?
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-09-01 : 06:43:34
this is ms sql server forums

post it in oracle related forums or www.dbforums.com
Go to Top of Page

rajasekhar857
Constraint Violating Yak Guru

396 Posts

Posted - 2009-09-01 : 07:08:26
can you help me out
Go to Top of Page
   

- Advertisement -