Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2006

    Unanswered: Inserting a field from one DB to another.

    Hi all,
    would love some guidance on what I thought would be a simple insert statement.
    I'm inserting some values that are created on the fly but the third value is actually pulled from another table from another Databse (but on the same server). I'm sure the spelling is correct (wouldn't be the first time) and the SQL error states it is the SELECT line that is throwing me off.
    I have tried the insert without the third field and it runs fine so i'm certain this is where it trips up.

    Is my syntax not correct? I could insert a duff value then use an update to correct it but isdrally i'd like this achieved in one hit.
    Any advice please?

    DECLARE @FValue varchar(50)

    SET @FValue = SELECT count(SomeField) FROM ADifferentDatabase.dbo.SomeTable

    INSERT INTO AnotherDB.dbo.AnotherTable
    Field01, Field02, Field03, Field04

    SELECT 'AValueFor01' AS Field01, 'AValueFor02' As Field02, @FValue AS Field03, 'AValueFor04' AS Field04



  2. #2
    Join Date
    Feb 2004
    In front of the computer
    Provided Answers: 54
    I'm better than 99% sure that you don't really want an @ in there!

    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  3. #3
    Join Date
    Sep 2006
    Thanks for the reply Pat.

    Looks like i'd left out the brackets () around the SELECT syntax.
    Work perfectly now.

    Thanks for your time.

Posting Permissions

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