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 3956648
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:23:25+00:00 2026-05-20T02:23:25+00:00

alright i built this stored procedure to take the columns from a stagging table

  • 0

alright i built this stored procedure to take the columns from a stagging table and copy them into my other table, but if these four columns are duplicates it wont insert the rows, works fine.

however, what i want to do is if only the tour, taskname and deptdate are the same, then i will update the rest of the information. and if all four columns are the same dont instert.

INSERT INTO dashboardtasks1
    SELECT [tour], [taskname], [deptdate], [tasktype], [desc], [duedate], [compdate], [comments], [agent], [compby], [graceperiod]
    FROM staggingtasks
    WHERE NOT EXISTS(SELECT * 
                     FROM dashboardtasks1 
                     WHERE (staggingtasks.tour=dashboardtasks1.tour and
                         staggingtasks.taskname=dashboardtasks1.taskname and 
    staggingtasks.deptdate=dashboardtasks1.deptdate and 
   staggingtasks.duedate=dashboardtasks1.duedate 
    )
                     )

i saw something like this

INSERT INTO table (a,b,c) VALUES (1,2,3)
  ON DUPLICATE KEY UPDATE c=c+1;

UPDATE table SET c=c+1 WHERE a=1;

but how could i do it if my stated 3 columns are the samed then update?

or is there a way to do this with an if statement and use 2 different queries, but how would my if statement work would it check if the row exists in the table i am uploading to and then run the insert statement?

or what if i did something like

alter PROCEDURE test

AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    -- Insert statements for procedure here


update dashboardtasks set
    duedate = s.duedate
from staggingtasks as s
    where s.tour=dashboardtasks.tour and
            s.taskname=dashboardtasks.taskname and 
        s.deptdate=dashboardtasks.deptdate


INSERT INTO dashboardtasks
SELECT [tour], [taskname], [deptdate], [tasktype], [desc], [duedate], [compdate], [comments], [agent], [compby], [graceperiod]
FROM staggingtasks
WHERE NOT EXISTS(SELECT * 
                 FROM dashboardtasks 
                 WHERE (staggingtasks.tour=dashboardtasks.tour and
                       staggingtasks.taskname=dashboardtasks.taskname and 
staggingtasks.deptdate=dashboardtasks.deptdate and 
staggingtasks.duedate=dashboardtasks.duedate 
)
                 )




END
GO

staging

 62 3647    Request Space   3/30/2011   Land    NULL    1/6/2010    NULL    NULL    PEGGYH      NULL    NULL

    81  505 Rel. Space  02/22/2012  Land    NULL    12/24/2011  NULL    NULL    IMANA       NULL    NULL

    82  505 Ticket  02/22/2012  Air NULL    1/8/2012    NULL    NULL    SYLVIAT     NULL    NULL

    83  505 Names to Airlines   02/22/2012  Air NULL    1/8/2012    NULL    NULL    SYLVIAT     NULL    NULL

    90  505 Names to Airlines   02/22/2012  Air NULL    1/1/2012    NULL    NULL    SYLVIAT     NULL    NULL

   92   505 Names to Airlines   02/22/2012  Air NULL    1/1/2012    NULL    NULL    SYLVIAT     NULL    NULL

table

1   3647    Request Space   3/30/2011   Land    NULL    11/6/2010   NULL    NULL    PEGGYH      NULL    NULL

    2   505 Rel. Space  02/22/2012  Land    NULL    11/24/2011  NULL    NULL    IMANA       NULL    NULL

    3   505 Ticket  02/22/2012  Air NULL    11/8/2012   NULL    NULL    SYLVIAT     NULL    NULL

    4   505 Names to Airlines   02/22/2012  Air NULL    11/8/2012   NULL    NULL    SYLVIAT     NULL    NULL

results

  1 3647    Request Space   3/30/2011   Land    NULL    1/6/2010    NULL    NULL    PEGGYH      NULL    NULL

    2   505 Rel. Space  02/22/2012  Land    NULL    12/24/2011  NULL    NULL    IMANA       NULL    NULL

    3   505 Ticket  02/22/2012  Air NULL    1/8/2012    NULL    NULL    SYLVIAT     NULL    NULL

    4   505 Names to Airlines   02/22/2012  Air NULL    1/8/2012    NULL    NULL    SYLVIAT     NULL    NULL

   5    505 Names to Airlines   02/22/2012  Air NULL    1/1/2012    NULL    NULL    SYLVIAT     NULL    NULL

   6    505 Names to Airlines   02/22/2012  Air NULL    1/1/2012    NULL    NULL    SYLVIAT     NULL    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-20T02:23:25+00:00Added an answer on May 20, 2026 at 2:23 am

    This might work for you.

    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 and
      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
                 )        
    
    
    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
                     )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright, I hope this isn't too broad a question but my curiosity got the
Alright so this is an odd one... I have an application built in ColdFusion
Alright. So I figure it's about time I get into unit testing, since everyone's
Alright, I'm trying to read a comma delimited file and then put that into
Alright. I have a query that looks like this: SELECT SUM(`order_items`.`quantity`) as `count`, `menu_items`.`name`
Alright, so I have a query that looks like this: SELECT `orders`.*, GROUP_CONCAT( CONCAT(
Alright, I don't know if anyone has tried to do this yet, however. I
Alright, I'm just trying to learn about using Contact information, but I'm a bit
Alright, currently I have my SWF hitting a php file that will go and
Alright, I have been doing the following (variable names have been changed): FileInputStream fis

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.