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)
 Help for a sintax error in a T-sql store procedure

Author  Topic 

mioara
Starting Member

3 Posts

Posted - 2008-02-06 : 07:41:10
Hi !
I have the folowing statements in a stored procedure that creates a view :


USE [Conel]
go
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[CompletareDateIndexeOrare]
AS
BEGIN
SET NOCOUNT ON;

if object_id('vIndexe') is not null
drop view vIndexe

CREATE VIEW vIndexe AS
Select *
from IndexeOrareZilnice
END


When I try to save the procedure , I receive the following error message :

Msg 156, Level 15, State 1, Procedure CompletareDateIndexeOrare
Incorrect syntax near the keyword 'VIEW'.
The statement with CREATE VIEW gives me this headaiche.

If I try the statement in a new query, it's ok.

So, which is my error, in the stored procedure ?

Thanks,
Mioara

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2008-02-06 : 07:44:21
You cannot create a view within a stored procedure. Why would you want to do this?

If you really need to do this, use dynamic sql.
Go to Top of Page
   

- Advertisement -