Solved

ALTER VIEW/Stored Procedure Problem

Posted on 2000-05-12
1
564 Views
Last Modified: 2012-05-05
I'm getting a "Syntax Error Near Keyword View" Error when I check the syntax of this Stored Procedure.  Can anyone tell me why?  Thank you so much!

Brian

CREATE PROCEDURE spGenerateReportData

      @StartTimeWindow DATETIME,
      @EndTimeWindow DATETIME,
      @Line varChar,
      @LineStatus varChar,
      @CauseType varChar,
      @Shift varChar,
      @Team varChar,
      @Lot varChar,
      @Product varChar

AS
BEGIN
IF EXISTS (SELECT NAME FROM objSystems WHERE NAME = 'qrySearchCriteria1')
ALTER VIEW qrySearchCriteria1 (Process_Area, Machine, Unit_Op, Auto_Cause, Occurrences)
      AS
      SELECT Process_Area, Machine, Unit_Op, Auto_Cause, Count(Start_Time) AS Occurrences
      FROM qrytblMachineDT
      WHERE (Start_DateTime > @StartTimeWindow) AND (Start_DateTime <= @EndTimeWindow)
      AND (Line IN (@Line)) AND (Line_Status IN (@LineStatus)) AND (Cause_Type IN (@CauseType))
      AND (Shift IN (@Shift)) AND (Team IN (@Team)) AND (Lot IN (@Lot)) AND (Product IN (@Product))
      GROUP BY Process_Area, Machine, Unit_Op, Auto_Cause
END
0
Comment
Question by:beercat2
1 Comment
 
LVL 4

Accepted Solution

by:
wqw earned 50 total points
ID: 2806251
no DDL allowed in stored procedures. sorry. here is my solution:

create table t1 (c1 int, c2 int)

create view v1 as select c1 from t1

create proc a
as
exec ('alter view v1 as select c2 from t1')

exec a

exec sp_helptext v1

Just wrap your DDL language in exec statement.

HTH,

</wqw>
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question