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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:43:26+00:00 2026-05-12T23:43:26+00:00

Ok, so you have something like this working. You Insert into a table from

  • 0

Ok, so you have something like this working. You Insert into a table from a tmp table, where the Equipment Number and the Account Number are missing…

Insert INTO ClientEquipments(
    SUB_ACCT_NO_SBB,
    EquipmentDate,
    EquipmentText,
    EquipmentNumber)
Select 
    replace(a.SUB_ACCT_NO_SBB,'"','') as SUB_ACCT_NO_SBB,
    getdate() as edate,'' as etext,
    replace(a.equipmentNumber,'"','')  equipmentNumber 
from clientspaymenttemp a 
where not exists 
    (select b.equipmentNumber 
    from clientEquipments b 
    where b.sub_acct_no_sbb=replace(a.SUB_ACCT_NO_SBB,'"','') and b.equipmentNumber=replace(a.equipmentNumber,'"',''))
group by SUB_ACCT_NO_SBB,equipmentNumber

But found a problem if the Equipment Number belonged to a different account number before, then my previous query will insert a new row, with the same Equipment Number but a new Account Number.

What I need it to do is simple:

  1. If Account Number and Equipment Number exists, leave it alone no need to insert.
  2. If Equipment Number exists, but it’s assigned to a different Account Number, delete the old row. (Import file handles assignments so I am 100% sure that it needs to be assigned to new account)

Something Like this added somewhere in the previous code:

DELETE FROM ClientEquipments
WHERE     (clientEquipmentId =
                          (SELECT     clientEquipmentId
                            FROM          ClientEquipments AS ClientEquipments_1
                            WHERE      (equipmentNumber = '0012345CAEC6')))
  1. If nothing exists then Insert a new row.

:::EDIT SOME MORE INFORMATION TO HELP ME OUT:::

I am reading a CSV file:

Sample Data:

Account | Name | Address | Some Extra Stuff | Equipment Number
"1234","First1,Last1","Address 1",etc etc... "ENum1234"
"1234","First1,Last1","Address 1",etc etc... "ENum5678"
"5678","First2,Last2","Address 2",etc etc... "ENum9123"
"9123","First3,Last3","Address 3",etc etc... "ENum4567"

This gets bulked imported into a temp table. (dbo.clients_temp)

Notice how account 1234 has 2 equipment numbers.

From here I insert new accounts into dbo.clients by doing a query from dbo.clients_temp to dbo.clients

Then I update dbo.clients with new information from dbo.clients_temp (ie Account 1234 might exists but now they have a new address.)

Now that my dbo.clients table is update with new clients, and new information for existing clients, I need to update my dbo.equipments table. I was originally doing what you see above, Insert Where Not Exists Account Number and Equipment Number.

Now the problem is that since equipments do change accounts, for example, Account Number 5678 might have become inactive which I don’t track or care for at the database level, but the equipment Number might now belong to Account Number 1234. In this case, my original query will insert a new row into the database, since Account 1234 and Equipment Number are not returned in the SELECT.

Ok, I have lost this now 😛 I will try and revisit the question later on the weekend because I just confused myself O.o

  • 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-12T23:43:26+00:00Added an answer on May 12, 2026 at 11:43 pm

    I had to modify Gordon’s answer above a bit, but that did the trick…

    Below is the relevant line of code that deletes the inactive accounts.

    DELETE FROM ClientEquipments WHERE EquipmentNumber =  
    (SELECT E.equipmentNumber FROM ClientEquipments As E INNER JOIN ClientsPaymentTemp AS T 
     on E.equipmentNumber = T.equipmentNumber and e.SUB_ACCT_NO_SBB <> T.SUB_ACCT_NO_SBB)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 431k
  • Answers 431k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try using the value of setincodebehind in your tag, like… May 15, 2026 at 2:13 pm
  • Editorial Team
    Editorial Team added an answer Others have already mentioned indexOf where you can do: <html><body><script… May 15, 2026 at 2:13 pm
  • Editorial Team
    Editorial Team added an answer You could do something like this: public IQueryable<Alphagram> GetCustomersWithAddresses() {… May 15, 2026 at 2:13 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.