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.
Author |
Topic |
shanmugaraj
Posting Yak Master
219 Posts |
Posted - 2013-04-18 : 04:45:07
|
Hi have an sp to create alter table statement.once the alter table statement is created, i need to execute the statement.create procedure sp_get_missing_columndeclare @str_alter_query varchar(max)BEGINset @str_alter_query = dept_id,location_idset @str_alter_query = 'Alter table temp_dynamic add '+replace(@str_alter_query, ',', ' nvarchar(max) , ') +' nvarchar(max)' EXEC @str_alter_query -- NOT WORKINGEND THANKSSHANMUGARAJnshanmugaraj@gmail.com |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-04-18 : 04:53:49
|
it should becreate procedure sp_get_missing_columndeclare @str_alter_query varchar(max)BEGINset @str_alter_query = 'dept_id,location_id'set @str_alter_query = 'Alter table temp_dynamic add '+replace(@str_alter_query, ',', ' nvarchar(max) , ') +' nvarchar(max)' EXEC @str_alter_query -- NOT WORKINGEND ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
shanmugaraj
Posting Yak Master
219 Posts |
Posted - 2013-04-18 : 05:02:47
|
The query is not executing and geting error exec sp_get_missing_column 'dept_id' error :Could not find stored procedure 'Alter table temp_dynamic add dept_id nvarchar(max)'.THANKSSHANMUGARAJnshanmugaraj@gmail.com |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-04-18 : 05:09:36
|
try with () around variablecreate procedure sp_get_missing_columndeclare @str_alter_query varchar(max)BEGINset @str_alter_query = 'dept_id,location_id'set @str_alter_query = 'Alter table temp_dynamic add '+replace(@str_alter_query, ',', ' nvarchar(max) , ') +' nvarchar(max)' EXEC (@str_alter_query) -- NOT WORKINGEND ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
shanmugaraj
Posting Yak Master
219 Posts |
Posted - 2013-04-18 : 05:23:56
|
SELECT @str_alter_query = 'Alter table temp_dynamic add '+replace(@str_alter_query, ',', ' nvarchar(max) , ') +' nvarchar(max)'THANKSSHANMUGARAJnshanmugaraj@gmail.com |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-04-18 : 05:32:23
|
did you try my suggestion? did it work?create procedure sp_get_missing_columndeclare @str_alter_query varchar(max)BEGINset @str_alter_query = 'dept_id,location_id'set @str_alter_query = 'Alter table temp_dynamic add '+replace(@str_alter_query, ',', ' nvarchar(max) , ') +' nvarchar(max)' EXEC (@str_alter_query) -- NOT WORKINGEND ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|
|
|