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 2000 Forums
 SQL Server Development (2000)
 Transact and DDL

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2003-05-16 : 09:37:48
Flavio writes "Using SQL SERVER 2000, how can I create a view within a stored procedure or triggers ?"

mtomeo
Starting Member

30 Posts

Posted - 2003-05-16 : 10:08:13
If I'm understanding you correctly, you want to pass some values into a Stored Proc and create a View from that? I would build a string that contains my Create View script so that I can supply variables and whatnot. Then use Exec() to execute the string/SQL Statement...

declare @SQL VarChar(1000)
select @SQL = 'CREATE VIEW....'
exec(@SQL)

I would assume you could do the same in a Trigger.

Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2003-05-16 : 19:55:07
OK, even if it allows you to create a view from within a trigger, WHY WHY WHY would you want to do that? That is about the worst idea I can think of. Not to mention the errors that will be thrown every time the trigger fires; since the view already exists CREATE VIEW will error out.

Go to Top of Page
   

- Advertisement -