SQL - Update

I am using Sql Server 2008.

I have a table that generates an ID. I want to get the generated identifier and save it in the bigint variable. How can i do this?

This is where Proc is stored, which gives the identifier as a result set. But I can not store it in the bigint variable.

ALTER PROC SCN.TRANSACTION_UNIQUE_ID_SELECT
AS

UPDATE COR.TRANSACTION_UNIQUE_ID
SET ID = ID + 1

OUTPUT INSERTED.ID AS ID
+5
source share
5 answers

If you want to use output, you can:

declare @ID table (ID bigint)

update the_table
  set ID = ID + 1
output INSERTED.ID into @ID

declare @bi bigint = (select ID from @ID)
+3
source

BigInt , SQL Server . rowID OUTPUT /.

.

( rowID ):

CREATE PROCEDURE [Sample].[Save] 
    (

     @rowID bigint OUTPUT

    )
AS
BEGIN

 SET NOCOUNT ON

 --Do your insert/update here


 --Set the RowID
 SET @rowID = (SELECT SCOPE_IDENTITY())

 END
+2

UPDATE ... ID , ?

@sign, SET @myvar = ...whatever...

0

OUTPUT INTO:

DECLARE @TblID TABLE ( ID int )

UPDATE COR.TRANSACTION_UNIQUE_ID
SET ID = ID + 1
OUTPUT INSERTED.ID INTO @TblID (ID) --the output values will be inserted 
                                    --into @TblID table-variable
0
DECLARE @id BIGINT
EXEC @id = SCN.TRANSACTION_UNIQUE_ID_SELECT 
-1

All Articles