GO causes error when used in EXEC: “Incorrect syntax near 'GO'.”

前端 未结 4 1483
被撕碎了的回忆
被撕碎了的回忆 2021-01-21 18:24

I\'ve created this stored procedure which dynamically creates the same trigger for all my tables:

USE [MyDatabase]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIE         


        
4条回答
  •  鱼传尺愫
    2021-01-21 18:33

    I got the same error, how i fixed this

    create or alter procedure mypro
    @msg varchar(20)
    as 
        print(@msg)
    go;
    exec mypro @msg='fft';
    

    output Incorrect syntax near 'go'

        Started executing query at Line 1   
        Msg 102, Level 15, State 1, Procedure mypro, Line 6
        Incorrect syntax near 'go'. 
    

    remove ; after go it will work.

    create or alter procedure mypro
    @msg varchar(20)
    as 
        print(@msg)
    go;
    exec mypro @msg='fft';
    
    [12:17:59 pm]   Started executing query at Line 1
        Commands completed successfully.
    [12:17:59 pm]   Started executing query at Line 7
        fft
        Total execution time: 00:00:00.062  
    

提交回复
热议问题