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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:49:42+00:00 2026-05-26T21:49:42+00:00

I create trigger CREATE TRIGGER PartnersTrigger on Partners INSTEAD OF INSERT AS BEGIN SET

  • 0

I create trigger

CREATE TRIGGER PartnersTrigger on Partners
INSTEAD OF INSERT
AS
BEGIN
SET NOCOUNT ON


Declare @Key nvarchar(10);

EXEC @Key = sp_GeneratePassword 5;

UPDATE Partners SET KeyInvitation  = @Key WHERE Id IN (SELECT Id FROM inserted);
INSERT INTO Partners(Email,KeyInvitation)
   SELECT Email, KeyInvitation
FROM inserted
END
GO

But I need set to KeyInvitation variable @Key.
And set sp_GeneratePassword 5 (procedure) in @Key.

How to do this?

UPDATE

CREATE PROCEDURE sp_GeneratePassword
 (
     @Length int
 )

 AS

 DECLARE @RandomID varchar(32)
 DECLARE @counter smallint
 DECLARE @RandomNumber float
 DECLARE @RandomNumberInt tinyint
 DECLARE @CurrentCharacter varchar(1)
 DECLARE @ValidCharacters varchar(255)
 SET @ValidCharacters = 'abcdefghijklmnopqrstuvwxyz0123456789'
 DECLARE @ValidCharactersLength int
 SET @ValidCharactersLength = len(@ValidCharacters)
 SET @CurrentCharacter = ''
 SET @RandomNumber = 0
 SET @RandomNumberInt = 0
 SET @RandomID = ''

 SET NOCOUNT ON

 SET @counter = 1

 WHILE @counter < (@Length + 1)

 BEGIN

         SET @RandomNumber = Rand()
         SET @RandomNumberInt = Convert(tinyint, ((@ValidCharactersLength - 1) * @RandomNumber + 1))

         SELECT @CurrentCharacter = SUBSTRING(@ValidCharacters, @RandomNumberInt, 1)

         SET @counter = @counter + 1

         SET @RandomID = @RandomID + @CurrentCharacter

 END

 SELECT @RandomID  AS 'Password'



GO

this not work:

Declare @Key nvar char(10);  -- can't post when I use "nvarchar" here
EXEC @Key = sp_GeneratePassword 5;

Error:

Incorrect syntax near ‘char’. Must declare the scalar variable “@Key”.
Must declare the scalar variable “@Key”. Must declare the scalar
variable “@Key”.

  • 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-26T21:49:42+00:00Added an answer on May 26, 2026 at 9:49 pm

    The trigger looks OK apart from the info noted by Michal Powaga and this bit:

    Declare @Key nvarchar(10);  -- can't post when I use "nvarchar" here
    EXEC @Key = sp_GeneratePassword 5;
    

    Unless sp_GeneratePassword has a RETURN with a specific value it will usually give 0 because this kind of call assigns the value from the RETURN to @Key. However, this can only be used for int values and @Key is nvarchar.

    I’d use an output parameter like in this answer from yesterday: Returning a value from a stored procedure

    Note; you are assigning all rows in the INSERT the same password (don’t assume triggers operate on single rows). I’d consider a DEFAULT constraint on the KeyInvitation column that calls a UDF. This avoids a trigger and will give different values (I assume)

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

Sidebar

Related Questions

CREATE TRIGGER dbo.YourTrigger ON a AFTER UPDATE AS BEGIN SET NOCOUNT ON; IF NOT
CREATE TRIGGER dbo.updateTrigger ON dbo.Education AFTER UPDATE AS BEGIN SET NOCOUNT ON; IF NOT
I've got the following trigger; CREATE TRIGGER trFLightAndDestination ON checkin_flight AFTER INSERT,UPDATE AS BEGIN
CREATE TRIGGER ChangesTracker on [SearchEngine].[Urls] FOR UPDATE, INSERT AS UPDATE [SearchEngine].[Urls] SET [IsNormalized] =
CREATE TRIGGER event_house_dealed AFTER UPDATE ON house FOR EACH ROW BEGIN DECLARE finished INT;
CREATE TRIGGER membership AFTER INSERT ON jos_config5 FOR EACH ROW BEGIN INSERT INTO jos_config4(
The line cmd.ExecuteNonQuery(); cmd.CommandText CREATE TRIGGER subscription_trig_0 ON subscription AFTER INSERT AS UPDATE user_data
I'm creating the following trigger: CREATE TRIGGER Trigger_UpdateTrainingDelivery AFTER DELETE OR INSERT OR UPDATE
how to create trigger in mysql in coldfusion at the time of insert, update
CREATE TRIGGER ATTENDANCE_INSERTION_TRIGGER ON course_enrollment AFTER INSERT AS BEGIN --insert **what just was inserted

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.