SELECT INTO Another Database Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mugs321
    New Member
    • Sep 2006
    • 22

    SELECT INTO Another Database Problem

    Hey all,
    I'm trying to use SELECT INTO to copy a table from one database to another. http://www.w3schools.com/sql/sql_select_into.asp tells me that I can do this using the IN keyword. I'm using MSSQL Server and the following statement:

    Code:
    SELECT RMC_Attempt.* INTO RMC_Attempt IN 'Test2'
    FROM RMC_Attempt
    I'm getting an "Incorrect syntax near the keyword 'IN'." error.

    Any thoughts?
  • jamesd0142
    Contributor
    • Sep 2007
    • 471

    #2
    Originally posted by Mugs321
    Hey all,
    I'm trying to use SELECT INTO to copy a table from one database to another. http://www.w3schools.com/sql/sql_select_into.asp tells me that I can do this using the IN keyword. I'm using MSSQL Server and the following statement:

    Code:
    SELECT RMC_Attempt.* INTO RMC_Attempt IN 'dbo.Test2'
    FROM RMC_Attempt
    I'm getting an "Incorrect syntax near the keyword 'IN'." error.

    Any thoughts?
    providing the table exists on the second database you can...
    [code=sql]
    insert into <databasename>. dbo.<tablename> select * from <databasename>. dbo.<tablename>
    [/code]

    Comment

    • ck9663
      Recognized Expert Specialist
      • Jun 2007
      • 2878

      #3
      Originally posted by Mugs321
      Hey all,
      I'm trying to use SELECT INTO to copy a table from one database to another. http://www.w3schools.com/sql/sql_select_into.asp tells me that I can do this using the IN keyword. I'm using MSSQL Server and the following statement:

      Code:
      SELECT RMC_Attempt.* INTO RMC_Attempt IN 'Test2'
      FROM RMC_Attempt
      I'm getting an "Incorrect syntax near the keyword 'IN'." error.

      Any thoughts?
      try

      select sourcetable.* into destinationdb.d bo.destinationt able
      from sourcedb.dbo.so urcetable

      Comment

      • Mugs321
        New Member
        • Sep 2006
        • 22

        #4
        Perfect guys! Both solutions work.

        Comment

        Working...