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 2012 Forums
 Transact-SQL (2012)
 create sp with alter statement

Author  Topic 

shanmugaraj
Posting Yak Master

219 Posts

Posted - 2013-04-17 : 03:06:58
/*
SELECT Name, dept_id, col_Name FROM temp_main
SELECT Name FROM temp_dynamic

exec sp_alter_table_column (Name,dept_id,salary,Age)

*/
create procedure sp_alter_table_column (@csv_column nvarchar(max))
as
declare @str_col_main nvarchar(max), @str_col_dynamic nvarchar(max) , @str_sql varchar(max)

begin

Select COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='temp_main'

Select COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='temp_dynamic'

--if the new column name are not found in temp_main, add new column in temp_dynamic . make sure temp_dynamic also doesnot have the new column

@str_sql = "Alter table temp_dynamic Add Column Dept_Id int NOT NULL, Desig_Id int NOT NULL"
exec @strsql
end

THANKS
SHANMUGARAJ
nshanmugaraj@gmail.com

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-04-17 : 08:55:03
Duplicate of http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=184613
Go to Top of Page
   

- Advertisement -