Solved

ALTER VIEW/Stored Procedure Problem

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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Database ERD 4 32
Access join syntax when converting to T-SQL query 4 37
SQL Dump exec output to table 3 23
SQL Log size 3 20
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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

820 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