I am trying to write a stored procedure to be called from a utility application on a dedicated server. I know that the create view statement alone is correct, but when placed in the context of a stored procedure, I get a syntax error. I do pretty much the same thing with a set of tables, and it works fine. Is it possible to create views using a stored procedure? If so, what am I missing about the syntax? I've been wrestling with this one for a while, any input would be greatly appreciated.
Query in question:
Errors:
Query in question:
Code:
CREATE PROCEDURE dbo.CreateDEViews
AS
IF .dbo.TableExists('vwPickDvdNew')=1
DROP VIEW vwPickDvdNew
IF .dbo.TableExists('vwPickDvdUsed')=1
DROP VIEW vwPickDvdUsed
IF .dbo.TableExists('vwPickVhsNewandUsed')=1
DROP VIEW vwPickVhsNewandUsed
CREATE VIEW dbo.vwPickDvdNew AS
SELECT dbo.PickTable.*
FROM dbo.PickTable
WHERE (fermat = 'DV')
CREATE VIEW dbo.vwPickDvdUsed AS
SELECT dbo.PickTable.*
FROM dbo.PickTable
WHERE (fermat = 'PD')
CREATE VIEW dbo.vwPickVhsNewAndUsed AS
SELECT dbo.PickTable.*
FROM dbo.PickTable
WHERE (fermat = 'V') OR (fermat = 'PV')
RETURN Null
Errors:
Code:
Server: Msg 156, Level 15, State 1, Procedure CreateDEViews, Line 10
Incorrect syntax near the keyword 'VIEW'.
Server: Msg 156, Level 15, State 1, Procedure CreateDEViews, Line 14
Incorrect syntax near the keyword 'VIEW'.
Server: Msg 156, Level 15, State 1, Procedure CreateDEViews, Line 18
Incorrect syntax near the keyword 'VIEW'.