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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:17:00+00:00 2026-05-26T10:17:00+00:00

I am working on triggers using SQL server 2005. I have a trigger for

  • 0

I am working on triggers using SQL server 2005. I have a trigger for a table which is after update. After declaring the variables, the code is like this.

if @isconfirmed_before = 0 and @isconfirmed_after = 1
begin

if @invite_userid <> ''
        begin

            select @points = points from dbo.InvitePoint where code = 'USR' and packageid = @packageid
            INSERT INTO InviteCount
                   ([userID]
                   ,[joinMerchantID]
                   ,[packageID]
                   ,[points]
                   ,[joinDate])
             VALUES
                   (@invite_userid
                   ,@merchantid
                   ,@packageid
                   ,@points
                   ,getdate())
        end

 SET @alpha_numeric=''
        SELECT @alpha_numeric=@alpha_numeric+CHAR(n) FROM
        (
            SELECT TOP 8 number AS n FROM master..spt_values
            WHERE TYPE='p' and (number between 48 and 57 or number between 65 and 90)
            ORDER BY NEWID()
        ) AS t 

        update merchant
        set reg_code = @alpha_numeric
        where merchantid = @merchantid

END

The last part of

    update merchant  
    set reg_code = @alpha_numeric
    where merchantid = @merchantid

This reg_code shoule be inserted only once when the row is inserted but it is changing every time there is an update to the table. How do i make it happen. Please help me, Thank you in advance!!

  • 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-26T10:17:01+00:00Added an answer on May 26, 2026 at 10:17 am
    update merchant   
    set reg_code = @alpha_numeric 
    where merchantid = @merchantid 
    

    That code is executing every time there is an update, because you have no conditional flow preventing it from executing sometimes. If you want to only execute that given a certain condition, you’ll need to wrap it in an IF block.

    You say: “This reg_code shoule be inserted only once when the row is inserted but it is changing every time there is an update to the table.” Why is that in an AFTER UPDATE trigger then? It looks like it should be in an AFTER INSERT trigger. Unless I am misunderstanding you.

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

Sidebar

Related Questions

I'm working on a trigger which needs to re-insert its data on another table.
In a project that I'm working, there's a table with a on update trigger,
Our application is using SQL Server 2005 as the database. We are using a
Recently I have been working with a SQL Server database and I was trying
I'm currently using Microsoft Sync Framework and everything is working fine except the SQL
Without using code, how can I turn this into a Template? I have about
When setting up replication in Sql Server 2008 the system creates triggers on every
I have a large SQL script that creates my database (multiple tables, triggers, and
I'm working on a project where I call a function which triggers a segfault.
I am working on a business app (asp.net). Right now I am using sql

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.