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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:11:30+00:00 2026-06-02T05:11:30+00:00

I have the following code in a cursor in SQL Server 2008 r2. begin

  • 0

I have the following code in a cursor in SQL Server 2008 r2.

begin 
    if exists (select * from GestionIOF with (updlock,serializable) where Fecha 
    =@fechagestion and ID_Desc2 = @id_tipoalarmas and ID_Modulo = @id_modulo)
    begin 
        update GestionIOF set Total = (Select Total from #Paso p where p.Fecha =   
        @fechagestion and p.Desc2 = @id_tipoalarmas and p.Modulo = @id_modulo), 
        Frecuencia = (Select Frecuencia from #Paso p where p.Fecha 
        = @fechagestion and p.Desc2 = @id_tipoalarmas 
        and p.Modulo = @id_modulo), Gestionado = 'False'
        where GestionIOF.Fecha = @fechagestion and GestionIOF.ID_Desc2 = 
        @id_tipoalarmas and GestionIOF.ID_Modulo = @id_modulo
    end
    else
    begin
        INSERT INTO GestionIOF(ID_Area,ID_Controlador ,ID_Modulo     
        ,ID_Desc2,ID_TipoEvento,Total,Frecuencia ,Fecha,Gestionado )
        SELECT * FROM #Paso 
    end

I check if the primary key exists and then if it doesn’t I insert it. But I am getting the following error:

Mens 2627, Nivel 14, Estado 1, Procedimiento InsertarGestionEC_IOF, Línea 67
Infracción de la restricción PRIMARY KEY ‘PK_GestionIOF’. No se puede insertar una clave duplicada en el objeto ‘dbo.GestionIOF’.

Maybe it is a bug. Any ideas?

  • 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-02T05:11:31+00:00Added an answer on June 2, 2026 at 5:11 am

    The exists clause is checking based on some input parameters @id_tipoalarmas and @id_modulo – but the insert clause in the else part of the statement is using #paso

    I would double check what is in #paso, since that could have multiple rows, but your input parameters is just 1 set of IDS. #paso could contain other ID’s you are not checking.

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

Sidebar

Related Questions

In the JDBC code, I have the following that is working with SQL Server:
I have the following lines of code: sql = source C:\\My Dropbox\\workspace\\projects\\hosted_inv\\create_site_db.sql cursor.execute (sql)
I have the following Python code: cursor.execute("INSERT INTO table VALUES var1, var2, var3,") where
I have the following code: import sqlite3 con = sqlite3.connect(testDB) cur = con.cursor() #cur.execute('CREATE
I have got the following SQL statement (SQL Server): DECLARE @atr nvarchar(255), @con nvarchar(1000),
I have the following recursion code, at each node I call sql query to
I currently have the following block of SQL 2005 code. What I need to
Let's say I have following code cursor = connection.cursor() cursor.execute(query) after that point I
I have been using the following code to query one table: public Cursor fetchFilteredItemsNearSortedByDistance(String
i have the following code and am trying to retrieve the cursor/mouse position when

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.