1、
GO (T-SQL)
Signals the end of a batch of Transact-SQL statements to the Microsoft® SQL Server™ utilities.Syntax
GORes
GO is not a Transact-SQL statement, it is a command recognized by the osql and isql utilities and SQL Server Query Analyzer.SQL Server utilities interpret GO as a signal that they should send the current batch of Transact-SQL statements to SQL Server. The current batch of statements is composed of all statements entered since the last GO, or since the start of the ad hoc session or script if this is the first GO. SQL Server Query Analyzer and the osql and isql command-prompt utilities implement GO differently. For more information, see osql Utility, isql Utility, and SQL Server Query Analyzer. A Transact-SQL statement cannot occupy the same line as a GO command. However, the line can contain comments.Users must follow the rules for batches. For example, any execution of a stored procedure after the first statement in a batch must include the EXECUTE keyword. The scope of local (user-defined) variables is limited to a batch, and cannot be referenced after a GO command.SQL Server applications can send multiple Transact-SQL statements to SQL Server for execution as a batch. The statements in the batch are then compiled into a single execution plan. Programmers executing ad hoc statements in the SQL Server utilities, or building scripts of Transact-SQL statements to run through the SQL Server utilities, use GO to signal the end of a batch.Applications based on the DB-Library, ODBC, or OLE DB APIs receive a syntax error if they attempt to execute a GO command. The SQL Server utilities never send a GO command to the server.Permissions
GO is a utility command that requires no permissions, it can be executed by any user.2、
你可以用游标,也可以建立临时表,然后去取其中的字段值作为存储过程的参数去调用就可以了

解决方案 »

  1.   

    当然有循环语句了
    declare @i int,
            @sum int
    select @i=0,@sum=0
    while @i<=100
    begin
     select @sum=@sum+@i
     select @i=@i+1
    endselect @sum
      

  2.   

    因为sql语句在执行前,先要分析批处理,然后根据批来编译,最后执行批处理。
    加go,可以使sqlserver在编译的时候,将其分开编译。
      

  3.   

    哦,这个可以不用循环来做。
    可以使用游标。
    declare cursor getfield for
    select 字段,..
    from tableopen getfield
    fetch next from getfield
    into @field,...--变量先声明while @@fetch_status=0
    begin
    [email protected]做你想做的处理
    end
    close getfield
    deallocate getfield