I have a table that has a newid() for the primary key field (Id)
in the stored procedure i need to return this newly created guid back as a return parameter, i could create the guid beforehand and insert into the database, but that would defeat the purpose of a newid(). Is there a good way to handle this?
INSERT INTO [SUBS].[dbo].[Subscriptions]
([CustomerId]
,[SubscriptionClassId]
,[StartDate]
,[TrialAmount]
,[Amount]
,[TrialInterval]
,[Interval]
,[TrialIntervalLength]
,[IntervalLength]
,[CreatedBy]
,[LastUpdatedBy])
VALUES
(@CustomerId
,@SubscriptionClassId
,@StartDate
,@TrialAmount
,@Amount
,@TrialInterval
,@Interval
,@TrialIntervalLength
,@IntervalLength
,@CreatedBy
,@CreatedBy)
select @SubscriptionId = SCOPE_IDENTITY() -- this does not work because scope_identity is numeric