Tuesday, February 14, 2012

Create View using Stored procedure

I would like to drop and re-create a view using stored procedure. I try with the following codes for creating view. but some its not working.
How can I drop the existing view befor creating it?

Declare @.sql_command nvarchar(4000)
Declare @.ParmDef nvarchar(4000)
Declare @.Branch int

Set @.sql_command =N'Create view [vwacchart] as ( Select * from ah where ah1=' + @.Pamvar + ')'
set @.parmdef =N'@.Pamvar int'
set @.branch=1

EXEC sp_executesql @.sql_command,@.parmdef,@.Pamvar= @.branchN'Create view [vwacchart] as ( Select * from ah where ah1=' + @.Pamvar + ')'

Or something like it. The text as shown in your post will not substitute in the @.variable, but be parsed as meaning =@.variable.

No comments:

Post a Comment