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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:51:53+00:00 2026-05-31T20:51:53+00:00

I am trying to insert data in table, but if it already exists in

  • 0

I am trying to insert data in table, but if it already exists in table, then it should not add.
This is the code, what I came up, but it still adds multiple data with same values.

insert into nol_art_izm([ART_ID],[DAT])
    select distinct
        v.id_art, {fn now()}
    from
        openxml(@hDoc, '/art_kompl/nol_voac') with #vc xd
        inner join nol_voac v on xd.id_art = v.id_art
    where
        not exists(select * from nol_art_izm where nol_art_izm.art_id=xd.id_art)

I want that there aren’t any duplicate “ART_ID” values

  • 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-31T20:51:54+00:00Added an answer on May 31, 2026 at 8:51 pm

    Try

    insert into nol_art_izm([ART_ID],[DAT])
        select distinct
            v.id_art, {fn now()}
        from
            openxml(@hDoc, '/art_kompl/nol_voac') with #vc xd
            inner join nol_voac v on xd.id_art = v.id_art
            left join nol_art_izm n on n.art_id = v.id_art
        where n.art_id is null
    

    Update:

    Try using GROUP BY to avoid duplicate id_art values:

    insert into nol_art_izm([ART_ID],[DAT])
        select
            v.id_art, MAX({fn now()})
        from
            openxml(@hDoc, '/art_kompl/nol_voac') with #vc xd
            inner join nol_voac v on xd.id_art = v.id_art
        where
            not exists(select * from nol_art_izm where nol_art_izm.art_id=xd.id_art)
        group by v.id_art
    

    Please not that I have chosen the MAX function for aggregating the {fn now()} values (in case there are more such values per id_art). You might want to use another function.

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

Sidebar

Related Questions

I am trying to insert data in table in mysql database through php code
I am trying to insert some text data into a table in SQL Server
I was trying to insert new data into an existing XML file, but it's
I am trying to take data from one mysql table and insert it in
I am trying to insert into Table A, unique data from Table B that
I was trying to insert some data into a table and I got the
i am trying to insert data to database but it removing braces'{}' while inserting
i am trying to insert some info into an sql server table but instead
I'm trying to insert a single row which may or may not already exist.
I have created a datatable and trying to insert that datatable through SqlBulkCopy but

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.