0

I'm executing sql scripts while using ADO and MSSQL server . Under Here you will find an first example of a multi lines sql statement like :

 use master;
 go;
 EXEC sp_detach_db
     @dbname=N'DATABASENAME';
 go;

I copy these lines from a Tmemo to my TADOQuery.sql.text but fail as already the go statement is not recognized and I get a keyword error by the mssql server. Can I run the whole sript as one TQquery or do I have th split my query into several pieces, separated by the semicolon and iterate through the whole text ?

Community
  • 1
  • 1
Franz
  • 1,883
  • 26
  • 47

2 Answers2

2

You have to split every statement whithout sending go. SQL-Server is not interpreting GO, this is done by MSSMS.

bummi
  • 27,123
  • 14
  • 62
  • 101
2

At first your code is not valid (no ; after GO) and has to be like this

USE master;
GO
EXEC sp_detach_db
    @dbname=N'DATABASENAME';
GO

In fact GO is a delimiter used by MSSMS to separate the SQL-Statements.

If you want to use the same scripts as MSSMS do, you have to work on that like MSSMS.

  1. Split the script into single parts by delimiter GO
  2. Send every part to the Database
Sir Rufo
  • 18,395
  • 2
  • 39
  • 73