1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Insert data from table1 to table2 depending on user_id and record_id

Discussion in 'Databases' started by garincha.03, Jun 10, 2016.

  1. #2
    So I need to insert some records from table1 to table2 depending on their user_id (PVKEY) and record_id (CNKEY). Just to explain better, every user has his own unique user_id (PVKEY) and every record has his own record_id (CNKEY). One user can have couple of records but everytime when the new record is added it needs to get new record_id (CNKEY) Everytime I try to insert I get message:

    "Cannot insert the value NULL into column 'CNKEY', table 'Progress.dbo.CONTHIST'; column does not allow nulls. INSERT fails. The statement has been terminated."

    Just to be sure that you'll understand the question better: user_id (PVKEY): data and system type is float, primary key FALSE, allow nulls TRUE. record_id (CNKEY): data and system type is float, primary key TRUE, allow nulls FALSE, record_id (CNKEY) exists only in table2 but not in table1 and user_id (PVKEY) exists in both tables. So here is my example that I was trying to execute it without any luck:

    INSERT INTO dbo.CONTHIST (PVKEY, CONTTYPE, ASSIGNEDTO, CONTDATE, SOURCE, NOTES, CNKEY)
    SELECT Pvkey, ContactType, AssignedTo, Date, SourceCode, ContactStatus
    FROM MopUpEOC
    WHERE PVKEY in (5,7,11)
     
    garincha.03, Jun 10, 2016 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,500
    Likes Received:
    4,460
    Best Answers:
    123
    Trophy Points:
    665
    #3
    You have 7 column names in the query for dbo.conthist but only select 6 from MopUpEOC
     
    sarahk, Jun 10, 2016 IP