I am writing a SP in SQL server
ALTER PROCEDURE [dbo].[spAddUserBadge]
AS
BEGIN
INSERT INTO dbo.SE_UserBadge
(
[UID],
BadgeID,
BadgeAssignmentOrRenewalDate,
BadgeExpiryDate ,
AmountPaid,
Remarks ,
AssignedBy
)
VALUES
(
17,1, 12-12-2012, 12-12-2013, 0.00, '', ''
)
SELECT SCOPE_IDENTITY() AS id
END
GO
SCOPE_IDENTITY is coming as NULL. where I am wrong?
The scope_identity will only return a value if there is a identity field, check you have an identity field.
Unfortunately, you cannot alter an existing column to be an identity field using sql. To do this, you have to create a new column using something like ALTER TABLE dbo.SE_UserBadge ADD column name INT IDENTITY(1,1). Then you have to transfer any existing values using IDENTITY_INSERT dbo.SE_UserBadge ON with an update statement. Then you can drop the old column.
Or you can use designer view in SSMS if the table isn’t too large.