SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 create sp with alter statement
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

shanmugaraj
Posting Yak Master

219 Posts

Posted - 04/17/2013 :  03:06:58  Show Profile  Send shanmugaraj a Yahoo! Message  Reply with Quote
/*
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
Flowing Fount of Yak Knowledge

3649 Posts

Posted - 04/17/2013 :  08:55:03  Show Profile  Reply with Quote
Duplicate of http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=184613
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000