Hi,
I have on sp to insert data, after inserting data i need to store my guid value in a variable but when i use.
I have set GUID value from Table design in ssms tool.
eg. set default constraints on column FamilyId (newid()).
I have set variable in sp
DECLARE @FamilyId VARCHAR(50) = NEWID();
But i do not want to use it.
Is there any alternate way to get guid without using this line.
--exec [dbo].[uspUserSave] 'ASDD@gmail.com','RAVI','9167876787'
ALTER PROCEDURE [dbo].[uspFamilySave] (
@Name VARCHAR(50)
,@Relationship VARCHAR(20)
,@PatientId VARCHAR(50)
,@CreatedBy VARCHAR(50)
)
AS
BEGIN
DECLARE @Msg VARCHAR(500);
DECLARE @FamilyId VARCHAR(50) = NEWID();
OPEN SYMMETRIC KEY EmployeeKey DECRYPTION BY CERTIFICATE EmployeeCertificate
DECLARE @ENCRYPT_KEY_ID NVARCHAR(100) = 'EmployeeKey'
SET NOCOUNT ON;
BEGIN TRY
BEGIN
INSERT INTO [dbo].[tblFamilyDetails] (
Name
,Relationship
,PatientId
,CreatedOn
,CreatedBy
)
VALUES (
@Name
,@Relationship
,@PatientId
,GETUTCDATE(),
@CreatedBy
)
SELECT 1 AS 'Status', 'Family Record Saved Successfully!' AS 'Message',@FamilyId as Data
END
END TRY
BEGIN CATCH
SET @Msg = Error_message();
DECLARE @ErrorSeverity INT = Error_severity();
DECLARE @ErrorState INT = Error_state();
RAISERROR (
@Msg
,@ErrorSeverity
,@ErrorState
);
END CATCH
END
Familyid is properly inserting but how can i get guid.
I have used SCOPE_IDENTITY(), @@Idenity but no use.