Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Why don't you insert <code>@Key</code> the way described below:</p> <p><strong>Edit</strong>: changed after @gbn answer</p> <p>Firstly, SP should look like this one bellow (it's all about <code>output</code> value):</p> <pre><code>CREATE PROCEDURE sp_GeneratePassword @param_in INT, @key_out NVARCHAR(10) OUTPUT AS BEGIN -- here is your password generation SET @key_out = 'your result' END GO </code></pre> <p><strong>Update</strong>: changed after @Deniskad explanation</p> <p>Your SP:</p> <pre><code>CREATE PROCEDURE sp_GeneratePassword @Length int, @RandomID varchar(32) OUTPUT AS DECLARE @counter smallint, @RandomNumber float, @RandomNumberInt tinyint, @CurrentCharacter varchar(1), @ValidCharacters varchar(255), @ValidCharactersLength int SET @ValidCharacters = 'abcdefghijklmnopqrstuvwxyz0123456789' SELECT @ValidCharactersLength = len(@ValidCharacters), @CurrentCharacter = '', @RandomNumber = 0, @RandomNumberInt = 0, @RandomID = '' SET NOCOUNT ON SET @counter = 1 WHILE @counter &lt; (@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 GO </code></pre> <p>..then trigger would look like this:</p> <pre><code>CREATE TRIGGER PartnersTrigger on Partners INSTEAD OF INSERT AS BEGIN SET NOCOUNT ON Declare @Key nvarchar(10); EXEC sp_GeneratePassword 5, @Key OUTPUT INSERT INTO Partners(Email,KeyInvitation) SELECT Email, @Key FROM inserted END GO </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload