Solved

ALTER VIEW/Stored Procedure Problem

Posted on 2000-05-12
1
567 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
I have a large data set and a SSIS package. How can I load this file in multi threading?
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.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

752 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