Using Alter View in sproc?

I am getting errors when trying to write a stored procedure with alter view statements in it. Can this not be done or is my syntax just off. If it can't be done is there a common work around or different method I should consider?

Thanks

[247 byte] By [bobbye] at [2008-2-22]
# 1
Can you post the stored procedure code that you're using?

Thanks,
- Balaji

BalajiRathakrishnan at 2007-9-9 > top of Msdn Tech,SQL Server,Transact-SQL...
# 2
You most probably have the ALTER VIEW in the body of the SP as static SQL statement. This is not possible since DDLs like ALTER VIEW, CREATE VIEW, CREATE PROCEDURE etc needs to be only DDL statement in the batch. You have to either do ALTER VIEW in it's own batch or execute it dynamically using EXECUTE or sp_executesql.
# 3

Umachandar,

I do have the ALTER VIEW statement in the body of the SP as static. I will rework the SP to execute it dynamically as you suggested.

Thanks alot

bobbye at 2007-9-9 > top of Msdn Tech,SQL Server,Transact-SQL...

SQL Server

Site Classified