Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2001
    Posts
    45

    Question Unanswered: SQL: INSERT INTO with VALUES *and* SELECT

    Via INSERT INTO .... SELECT ... WHERE .... I managed to fill in missing entries in a table. Now I would like to fill in some other fields of those newly created entries - at the same time.... kind of a combination of SELECT *and* VALUES ()...

    Does anybody know how to accomplish this?

    This is how far I got:

    INSERT INTO [tblB] SELECT [tblA].[ID] AS [ID] FROM [tblA] WHERE [ID] NOT IN (SELECT [ID] FROM [tblB]);

    (I imagine some addition like ", ([strVariable]) VALUES ('Defaultvalue')")

  2. #2
    Join Date
    Apr 2002
    Location
    Germany
    Posts
    228
    You can just place the constants you'd have in the VALUES statement in the SELECT as in:

    INSERT INTO [tblB] SELECT [tblA].[ID] AS [ID], 1234 AS [Field1], 5678 AS [Field2], 'somenicetext' AS [Text1] FROM [tblA] WHERE [ID] NOT IN (SELECT [ID] FROM [tblB]);

  3. #3
    Join Date
    Nov 2001
    Posts
    45
    That's it! You are my hero! Thanks a lot!

Posting Permissions

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