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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:32:30+00:00 2026-06-03T20:32:30+00:00

I have a sql database that querys the histroy data of engines. One of

  • 0

I have a sql database that querys the histroy data of engines. One of the features is that on a daily basis a stored procedure will search through all the data for a specific event and if the event is found it will insert it into a new table.

The problem is that this data must be unique…

The Table headers are as below:

ID / ID_Location / IDDown / IDUp / DtDown / DtUp / TimeDifference / IsExempt / Reason / Details / OrigDtUp

And the sql query is:

insert into exempts(ID_Location, iddown, idup, dtdown, dtup, timedifference)
select ID_Location, iddown, idup, dtdown, dtup, DATEDIFF(MINUTE, dtdown, dtup) as timedifference
from @tmptbl
except
select ID_Location, iddown, idup, dtdown, dtup, timedifference from exempts

But I need the query to check both the DtUp and OrigDtUp columns and ignore the timedifference as the user can change the DtUp to any value in a list and the origional DtUp value moves to OrigDtUp therfore the record is now different and the records is reinserted but with the original values??

Thanks in advance!!
Neil

  • 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-06-03T20:32:32+00:00Added an answer on June 3, 2026 at 8:32 pm

    Use a left join, it’s easier to see the logic:

       insert into exempts(ID_Location, iddown, idup, dtdown, dtup, timedifference) 
        select t.ID_Location, t.iddown, t.idup, t.dtdown, t.dtup, DATEDIFF(MINUTE, dtdown, dtup) as timedifference 
        from @tmptbl as t
          left join exempts as e 
            on  t.ID_Location = e.ID_Location 
            and t.iddown = e.iddown
            and t.idup = e.idup
            and t.dtdown = e. dtdown
            and t.DtUp = e.OrigDtUp --  <<  Match diff columns here
        where t.ID_Location is null
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a SQL database that queries the history data of engines. One of
I have a SQL Server 2000 database that will not display the column list
I have a SQL Server 2005 database that stores data for multiple users. Each
I need to be able to have an SQL query that searches my database
Possible Duplicate: SQL Server Database query help Hi, I have a problem that I
I have a SQL database that has a table with a field set to
I have a SQL database that has the following table: Table: PhoneRecords -------------- ID(identity
I have a typical dev scenario: I have a SQL 2008 database that I
I have a SQL Server 2005 database that has been deleted, and I need
I have an MS SQL 2000 database that was backed up from a public

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.