Solved

ALTER VIEW/Stored Procedure Problem

Posted on 2000-05-12
1
562 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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
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…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now