I have the following query:
INSERT INTO dbo.Products 
        ( Code , 
          ProducerCode , 
          CustomerId , 
          EanCode , 
          ChangedDateTime , 
          ChangedById , 
          Deleted  
        ) 
SELECT  Code , 
        ProducerCode , 
        CustomerId , 
        EanCode , 
        GETDATE(), 
        GETDATE(),
        0 
FROM dbo.BulkProducts 
WHERE ProductId is NULL AND BulkProducts.BulkId = @BulkId
The Products table has an IDENTITY ID column, which is assigned automatically on insert. What I want to achieve is, after the insertion in Products, have the assigned ID of the product in the row from BulkProducts. I have read a bit about@@IDENTITY, IDENT_CURRENT and SCOPE_IDENTITY but I cannot seem to get it to work for my example. Any help appreciated. I am using SQL Server 2012.
 
    