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
 Transact-SQL (2000)
 create procedure syntax

Author  Topic 

abolk
Starting Member

1 Post

Posted - 2004-12-01 : 13:26:43
I am trying to create a procedure that alters a view and am going crazy!! The code below is modified but still has the same idea.

CREATE PROCEDURE dbo.ICS_history_views as

create VIEW dbo.vw_History_200409_test AS

SELECT * from tbl_history_200409

I am getting an error message saying Incorrect syntax near the keyword 'VIEW'.

If I run the code without the create procedure statement it runs fine. What am I missing???

Thanks!!!!

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-12-01 : 13:53:40
try this

CREATE PROCEDURE dbo.ICS_history_views as

exec('create VIEW dbo.vw_History_200409_test AS
SELECT * from tbl_history_200409')


Go with the flow & have fun! Else fight the flow
Go to Top of Page

Hippi
Yak Posting Veteran

63 Posts

Posted - 2004-12-01 : 15:12:16
quote:
Originally posted by spirit1

try this

CREATE PROCEDURE dbo.ICS_history_views as

exec('create VIEW dbo.vw_History_200409_test AS
SELECT * from tbl_history_200409')


Go with the flow & have fun! Else fight the flow


I am new to SQL server.
I don't know why we need to use dynamic sql here.
Thank you.
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-12-01 : 15:49:17
you have
create VIEW dbo.vw_History_200409_test AS which gives an error.

so you have to put it in another batch

Go with the flow & have fun! Else fight the flow
Go to Top of Page

Hippi
Yak Posting Veteran

63 Posts

Posted - 2004-12-01 : 18:43:15
quote:
Originally posted by spirit1

you have
create VIEW dbo.vw_History_200409_test AS which gives an error.

so you have to put it in another batch

Go with the flow & have fun! Else fight the flow


So u mean we have to use dynamic sql to create a view in a procedure?
Thank you.
Go to Top of Page
   

- Advertisement -