I have the following code in a trigger, however I am getting the error
Afer this line
Code:
Msg 156, Level 15, State 1, Procedure AddCertificateNumber, Line 28
Incorrect syntax near the keyword 'SELECT'.
Afer this line
Code:
SET @Upper = 9999999 ---- The highest random number
Code:
USE [hmtcms]
GO
/****** Object: Trigger [dbo].[AddCertificateNumber] Script Date: 05/13/2013 22:32:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dbo].[AddCertificateNumber] ON [dbo].[tblCertificates]
AFTER INSERT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- get the last id value of the record inserted or updated
DECLARE @id INT
SELECT @id = [CertificateId]
FROM INSERTED
---- Create the variables for the random number generation
DECLARE @Random INT;
DECLARE @Upper INT;
DECLARE @Lower INT
---- This will create a random number between 1 and 999
SET @Lower = 1000000 ---- The lowest random number
SET @Upper = 9999999 ---- The highest random number
SELECT @Random = ROUND(((@Upper - @Lower -1) * RAND() + @Lower), 0)
SELECT @Random
-- Insert statements for trigger here
UPDATE tblCertificates
SET tblCertificates.CertificateNumber = SELECT @Random
WHERE [CertificateId] = @id
END