Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3853856
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:32:02+00:00 2026-05-19T17:32:02+00:00

I have two tables with the exact same columns. Both have primary identity keys

  • 0

I have two tables with the exact same columns.

Both have primary identity keys called id that auto increment.

My program adds data to a stagging table and then filters what gets added to the task table through this procedure.

Mmy problem is
I have this update statement followed by an insert,
for some reason my update statement does not work, when it is in the procedure by itself.

My insert statement works when it is by itself in the procedure but not when underneath this update statement.

I want my update statement to

Update my duedate in my dashboardtasks table,
if these 3 fields match in the row
tour
deptdate
taskname

If the row being added does not match in these 3 fields than insert the row as a new row using my insert statement underneath.

 update dashboardtasks set
         deptdate = s.deptdate,
         tour = s.tour,
          tasktype = s.tasktype,
          [desc] = s.[desc],
          duedate = s.duedate,
          compdate = s.compdate,
          comments = s.comments,
          agent = s.agent,
          compby = s.compby,
          graceperiod    = s.graceperiod
        from staggingtasks as s
        where
          s.tour=dashboardtasks.tour and
          s.taskname=dashboardtasks.taskname and 
          s.deptdate=dashboardtasks.deptdate 


        insert into dashboardtasks (tour, taskname, deptdate, tasktype, [desc], duedate, compdate, comments, agent, compby, graceperiod)
        select tour, taskname, deptdate, tasktype, [desc], duedate, compdate, comments, agent, compby, graceperiod
        from staggingtasks as s
        where not exists (select *
                          from dashboardtasks as d
                          where s.tour=d.tour and
                                s.taskname=d.taskname and 
                                s.deptdate=d.deptdate and
                                s.duedate=d.duedate
                         )


id int Unchecked
tour varchar(50) Checked
taskname varchar(50) Checked
deptdate varchar(50) Checked
tasktype varchar(50) Checked
[desc] varchar(MAX) Checked
duedate varchar(50) Checked
compdate varchar(50) Checked
comments varchar(MAX) Checked
agent varchar(50) Checked
compby varchar(50) Checked
graceperiod varchar(50) Checked

these are my fields, but compby, comments, compdate, and desc are null

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T17:32:03+00:00Added an answer on May 19, 2026 at 5:32 pm

    Here is a run through with your queries.

    Set up test data

    create table dashboardtasks1(id int identity, tour int, taskname nvarchar(50), deptdate datetime, tasktype nvarchar(50), [desc] nvarchar(50), duedate datetime, compdate datetime, comments nvarchar(50), agent nvarchar(50), compby int, graceperiod int)
    create table staggingtasks(id int, tour int, taskname nvarchar(50), deptdate datetime, tasktype nvarchar(50), [desc] nvarchar(50), duedate datetime, compdate datetime, comments nvarchar(50), agent nvarchar(50), compby int, graceperiod int)
    
    insert into staggingtasks(id, tour, taskname, deptdate, tasktype, [desc], duedate, compdate, comments, agent, compby, graceperiod)
        values (62, 3647, 'Request Space', '2011-03-30', 'Land', NULL, '2010-01-06', NULL, NULL, 'PEGGYH', NULL, NULL)
    insert into staggingtasks(id, tour, taskname, deptdate, tasktype, [desc], duedate, compdate, comments, agent, compby, graceperiod)
        values (81, 505, 'Rel. Space', '2012-02-22', 'Land', NULL, '2011-12-24', NULL, NULL, 'IMANA', NULL, NULL)
    insert into staggingtasks(id, tour, taskname, deptdate, tasktype, [desc], duedate, compdate, comments, agent, compby, graceperiod)
        values (82, 505, 'Ticket', '2012-02-22', 'Air', NULL, '2012-01-08', NULL, NULL, 'SYLVIAT', NULL, NULL)
    insert into staggingtasks(id, tour, taskname, deptdate, tasktype, [desc], duedate, compdate, comments, agent, compby, graceperiod)
        values (83, 505, 'Names to Airlines', '2012-02-22', 'Air', NULL, '2012-01-08', NULL, NULL, 'SYLVIAT', NULL, NULL)
    insert into staggingtasks(id, tour, taskname, deptdate, tasktype, [desc], duedate, compdate, comments, agent, compby, graceperiod)
        values (90, 505, 'Names to Airlines', '2012-02-22', 'Air', NULL, '2012-01-01', NULL, NULL, 'SYLVIAT', NULL, NULL)
    insert into staggingtasks(id, tour, taskname, deptdate, tasktype, [desc], duedate, compdate, comments, agent, compby, graceperiod)
        values (92, 505, 'Names to Airlines', '2012-02-22', 'Air', NULL, '2012-01-01', NULL, NULL, 'SYLVIAT', NULL, NULL)
    
    insert into dashboardtasks1(tour, taskname, deptdate, tasktype, [desc], duedate, compdate, comments, agent, compby, graceperiod)
        values (3647, 'Request Space', '2011-03-30', 'Land', NULL, '2010-11-06', NULL, NULL, 'PEGGYH', NULL, NULL)
    insert into dashboardtasks1(tour, taskname, deptdate, tasktype, [desc], duedate, compdate, comments, agent, compby, graceperiod)
        values (505, 'Rel. Space', '2012-02-22', 'Land', NULL, '2011-11-24', NULL, NULL, 'IMANA', NULL, NULL)
    insert into dashboardtasks1(tour, taskname, deptdate, tasktype, [desc], duedate, compdate, comments, agent, compby, graceperiod)
        values (505, 'Ticket', '2012-02-22', 'Air', NULL, '2012-11-08', NULL, NULL, 'SYLVIAT', NULL, NULL)
    insert into dashboardtasks1(tour, taskname, deptdate, tasktype, [desc], duedate, compdate, comments, agent, compby, graceperiod)
        values (505, 'Names to Airlines', '2012-02-22', 'Air', NULL, '2012-11-08', NULL, NULL, 'SYLVIAT', NULL, NULL)
    

    Run the update statement

    update dashboardtasks1 set
      tasktype = s.tasktype,
      [desc] = s.[desc],
      duedate = s.duedate,
      compdate = s.compdate,
      comments = s.comments,
      agent = s.agent,
      compby = s.compby,
      graceperiod    = s.graceperiod
    from staggingtasks as s
    where
      s.tour=dashboardtasks1.tour and
      s.taskname=dashboardtasks1.taskname and 
      s.deptdate=dashboardtasks1.deptdate
    

    Four rows affected. A select from dashboardtasks1 gives you this result

    id  tour    taskname    deptdate    tasktype    desc    duedate compdate    comments    agent   compby  graceperiod
    1   3647    Request Space   2011-03-30 00:00:00.000 Land    NULL    2010-01-06 00:00:00.000 NULL    NULL    PEGGYH  NULL    NULL
    2   505 Rel. Space  2012-02-22 00:00:00.000 Land    NULL    2011-12-24 00:00:00.000 NULL    NULL    IMANA   NULL    NULL
    3   505 Ticket  2012-02-22 00:00:00.000 Air NULL    2012-01-08 00:00:00.000 NULL    NULL    SYLVIAT NULL    NULL
    4   505 Names to Airlines   2012-02-22 00:00:00.000 Air NULL    2012-01-08 00:00:00.000 NULL    NULL    SYLVIAT NULL    NULL
    

    Run the insert statement

    insert into dashboardtasks1 (tour, taskname, deptdate, tasktype, [desc], duedate, compdate, comments, agent, compby, graceperiod)
    select tour, taskname, deptdate, tasktype, [desc], duedate, compdate, comments, agent, compby, graceperiod
    from staggingtasks as s
    where not exists (select *
                      from dashboardtasks1 as d
                      where s.tour=d.tour and
                            s.taskname=d.taskname and 
                            s.deptdate=d.deptdate and
                            s.duedate=d.duedate
                     )
    

    Two rows are affected. A query against dashboardtasks1 gives you this result.

    id  tour    taskname    deptdate    tasktype    desc    duedate compdate    comments    agent   compby  graceperiod
    1   3647    Request Space   2011-03-30 00:00:00.000 Land    NULL    2010-01-06 00:00:00.000 NULL    NULL    PEGGYH  NULL    NULL
    2   505 Rel. Space  2012-02-22 00:00:00.000 Land    NULL    2011-12-24 00:00:00.000 NULL    NULL    IMANA   NULL    NULL
    3   505 Ticket  2012-02-22 00:00:00.000 Air NULL    2012-01-08 00:00:00.000 NULL    NULL    SYLVIAT NULL    NULL
    4   505 Names to Airlines   2012-02-22 00:00:00.000 Air NULL    2012-01-08 00:00:00.000 NULL    NULL    SYLVIAT NULL    NULL
    5   505 Names to Airlines   2012-02-22 00:00:00.000 Air NULL    2012-01-01 00:00:00.000 NULL    NULL    SYLVIAT NULL    NULL
    6   505 Names to Airlines   2012-02-22 00:00:00.000 Air NULL    2012-01-01 00:00:00.000 NULL    NULL    SYLVIAT NULL    NULL
    

    Is this the expected behavior/result?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables, A and B. Both have the exact same columns. I
I have two tables which have the exact same structure. Both tables can store
I have two tables that are joined together. A has many B Normally you
I have two tables, both with start time and end time fields. I need
I have two tables in my database, called ratings and movies . Ratings: |
I have two tables, one that contains volunteers, and one that contains venues. Volunteers
I have two tables say, t1 and t2 that have t1.t1_id and t2.t2_id as
I have two tables table1 = records, table2 = duplicates. Both tables contain a
I have two tables, Book and Tag , and books are tagged using the
We have two Tables: Document: id, title, document_type_id, showon_id DocumentType: id, name Relationship: DocumentType

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.