If our statement is:
IF not EXISTS (SELECT 1 from sys.views WHERE name= ' report_individualticket ')
BEGIN
CREATE View Report_ Individualticket
as
SELECT ticket.ticketnumber, Ticket.ticketid,
gisprocess.stagename,
Content.dtreceived, Content.contenttext
from
(gisprocess INNER JOIN Ticket on
gisprocess.ticketid= Ticket.ticketid)
INNER JOIN Content on
ticket.contentid=content.contentid
end
The following error is prompted:
MSG 156, level, State 1, line 4
Incorrect syntax near the keyword ' view '.
The reason for this error is that the "CREATE view" sentence must be the first sentence in batch processing.
So you can modify the statement to:
IF EXISTS (SELECT 1 from sys.views WHERE name= ' report_individualticket ') DROP VIEW Report_
Individualticket go CREATE view report_individualticket as SELECT Ticket.ticketnumber, Ticket.ticketid, Gisprocess.stagename, Content.dtreceived, Content.contenttext from (gisprocess INNER JOIN Ticket on Gisprocess.ticketid =ticket.ticketid) INNER JOIN Content on Ticket.contentid=content.contentid go