Results 1 to 2 of 2

Thread: execute problem

  1. #1
    Join Date
    Dec 2001
    Location
    Canada
    Posts
    45

    Unhappy Unanswered: execute problem

    I whan to run this code, but it still doesn't work.

    Code:
    DECLARE @MyText VARCHAR(1000)
    SET @MyText = 'SET IDENTITY_INSERT [Table1] ON ' + CHAR(13)  + ' GO'
    
    EXEC(@MyText)
    MSSQL doesn't like the "GO"

    Thanks
    Franky
    FBoucheros@hotmail.com

  2. #2
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Why do you need the GO?

    Code:
    USE Northwind
    GO
    
    SET NOCOUNT ON
    CREATE TABLE myTable99(Col1 int IDENTITY(1,1), Col2 char(1))
    GO
    
    DECLARE @mySQL99 VARCHAR(1000)
    SET @mySQL99 = 'SET IDENTITY_INSERT myTable99 ON INSERT INTO myTable99(Col1,Col2) SELECT 1,''A''' 
    	+ ' SELECT * FROM myTable99'
    SELECT @mySQL99
    EXEC(@mySQL99)
    GO
    
    SET NOCOUNT OFF
    DROP TABLE myTable99
    GO
    And why would you do dynamic sql for this anyway?
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •