SQL Server first determines whether a view exists and then creates a statement for the view _mssql

Source: Internet
Author: User
Tags ticket

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 
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.