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)
 ALTER VIEW from PROCEDURE CODE

Author  Topic 

koushik
Starting Member

11 Posts

Posted - 2010-09-14 : 08:10:24
Hi,

Can you please let me know how to alter a view from a procedure code.



Regards,
Koushik Chandra

kunal.mehta
Yak Posting Veteran

83 Posts

Posted - 2010-09-14 : 08:30:54
use execute immedaiate
Go to Top of Page

koushik
Starting Member

11 Posts

Posted - 2010-09-14 : 08:46:41
Can you please provide the syntax for this as the "Immediate" is seems to be not a keyword in SQL Server 2005


Regards,
Koushik Chandra
Go to Top of Page

kunal.mehta
Yak Posting Veteran

83 Posts

Posted - 2010-09-14 : 09:05:59
declare @sql as nvarchar(100)
set @sql='select * from tbl_UserRoles'
EXECUTE sp_executesql @sql
Go to Top of Page

kunal.mehta
Yak Posting Veteran

83 Posts

Posted - 2010-09-14 : 09:16:00
declare @sql as nvarchar(100)
set @sql='create view testview as select * from tbl_UserRoles'
EXECUTE sp_executesql @sql
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-09-14 : 09:25:27
quote:
Originally posted by kunal.mehta

use execute immedaiate


Execute immediate is for mysql and ORACLE

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

kunal.mehta
Yak Posting Veteran

83 Posts

Posted - 2010-09-14 : 09:31:32
use EXECUTE sp_executesql @sql for sql server
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-09-14 : 09:36:19
quote:
Originally posted by koushik

Hi,

Can you please let me know how to alter a view from a procedure code.



Regards,
Koushik Chandra


Why do you want to alter a view from a stored procedure?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

koushik
Starting Member

11 Posts

Posted - 2010-09-15 : 04:34:20
I want to change the source table name in the alter view statement. e.g. View Created like : Create View v1 as select * from tab1

In the Alter view starement I want "Alter View V1 as select * from t2"

Regards,
Koushik Chandra
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-09-15 : 09:19:48
quote:
Originally posted by koushik

I want to change the source table name in the alter view statement. e.g. View Created like : Create View v1 as select * from tab1

In the Alter view starement I want "Alter View V1 as select * from t2"

Regards,
Koushik Chandra


You can do it as a independent statement. I dont see any point in using a Stored procedure for this

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -