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

  • Home
  • SEARCH
  • 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 7927853
In Process

The Archive Base Latest Questions

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

The following query does not fail but does not insert the unique values either.

  • 0

The following query does not fail but does not insert the unique values either.

I only want to insert unique values

DECLARE @user_id AS varchar(80) 
DECLARE @real_name as varchar(250) 

–New Unique values are “aaa” and they do not exist in the target table

SET @user_id = 'aaa'
SET @real_name = 'aaa'

INSERT INTO TargetTable
  ([user_id],real_name)
SELECT @user_id, @real_name
WHERE NOT EXISTS
  (SELECT [user_id],real_name FROM TargetTable)
  • 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-03T19:32:08+00:00Added an answer on June 3, 2026 at 7:32 pm

    If you’re having problem with the insert the way you doing, try a different approach like this:

    -- if the count of records with that @user_id and @real_name is less or equal to 0, 
    -- that means it's not in the table
    IF (0 >= (SELECT COUNT(*) FROM TargetTable WHERE @user_id = [user_id] AND @real_name = [real_name]))
    BEGIN
       -- then call a normal insert
       INSERT
         INTO TargetTable ([user_id], real_name )
       VALUES             (@user_id , @real_name)
    
    END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following query does not return any result SELECT user_id FROM test WHERE poll_id
I am wondering why the following regex does not match. string query = \1
The following query does not update the datetime field: update table SET EndDate =
The following query does not work, and produces an error: A transport-level error has
The following query does not work and it keeps giving a weird error: keys
LINQ drives me crazy. Why does following query not return the duplicates, whereas it
In the following example, why does the min() query return results, but the max()
Following query does not work in access. SELECT Fields.FieldId, PrecisionSettings.DecimalPlaces from Fields left outer
Why does the following query raise the error below for a row with a
Does anyone know why the following query fails in Derby? delete from MyTable where

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.