view problem

  • Hi,

    if exists (select * from sysobjects where type = 'V' and name = 'SerialControlView')

    Begin

    ALTER VIEW dbo.SerialControlView AS

    SELECT UserId, Choice AS Secim, PdfId FROM dbo.SerialControl WHERE RIGHT(PdfId, LEN('MEMO??!!.pdf'))= 'MEMO0304.pdf'

    End

    Else

    Begin

    CREATE VIEW dbo.SerialControlView AS

    SELECT UserId, Choice AS Secim, PdfId FROM dbo.SerialControl WHERE RIGHT(PdfId, LEN('MEMO??!!.pdf'))= 'MEMO0304.pdf'

    End

    --------------------------------

    Server: Msg 156, Level 15, State 1, Line 3

    Incorrect syntax near the keyword 'VIEW'.

    Server: Msg 156, Level 15, State 1, Line 8

    Incorrect syntax near the keyword 'VIEW'.

    what is the problem?

  • ALTER VIEW, CREATE VIEW and a whole host of other statements must be the only statements in a batch. Try this instead:-

    if exists (select * from sysobjects where type = 'V' and name = 'SerialControlView')

    drop view SerialControlView

    go

    CREATE VIEW dbo.SerialControlView AS

    SELECT UserId, Choice AS Secim, PdfId FROM dbo.SerialControl WHERE RIGHT(PdfId, LEN('MEMO??!!.pdf'))= 'MEMO0304.pdf'

    go

  • very thanks ianscarlett.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply