Question: I'm using this query:

```
INSERT INTO [LepidoliteDB].[dbo].[EGelLayerWeighingData] ([EGelWeighingDataID], [Amount], [ContainerID], [Portions],
[PortionNumber], [Canceled], [LayerID], [WeighingDone], [InsertDone],
[MeasuresDone], [StartDateAndTime], [EndDateAndTime]) 
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);

SELECT SCOPE_IDENTITY()

```

But `SCOPE_IDENTITY()` always returns 1.

What am I missing?

Answer: 
Best way to write it is ..

```
RETURN  SCOPE_IDENTITY()  

```

You can also use `@@IDENTITY` and `IDENT_CURRENT` for this 

SCOPE\_IDENTITY, IDENT\_CURRENT, and @@IDENTITY are similar functions because they return values that are inserted into identity columns.

IDENT\_CURRENT is not limited by scope and session; it is limited to a specified table. IDENT\_CURRENT returns the value generated for a specific table in any session and any scope. For more information, see IDENT\_CURRENT (Transact-SQL).

SCOPE\_IDENTITY and @@IDENTITY return the last identity values that are generated in any table in the current session. However, SCOPE\_IDENTITY returns values inserted only within the current scope; @@IDENTITY is not limited to a specific scope.

Therefore RETURN SCOPE\_IDENTITY() is the best one.
I had this problem and I must admit it was a dumb mistake, but I thought it may happen to someone else. I was using the Execute command that returns the number of rows affected instead of a Query command.

By the way, I was combining my Insert and SELECT SCOPE\_IDENTITY() together in one command, which is why I started with the Execute command. I was still able to combine them, but I used ExecuteScalar instead.