This is a follow up to my previous question, in t-sql
SELECT SCOPE_IDENTITY()
returns a BIGINT, I did the following to get it to return an INT:
DECLARE @X INT
INSERT ...
SELECT @X = SCOPE_IDENTITY()
-- if i don't include the line below, it will return a BIGINT
SELECT @X
Why does it return a BIGINT unless I do SELECT @X at the end?
p.s. turns out
SELECT @X = SCOPE_IDENTITY()
doesn’t return anything, it just sets @x
returns a BIGINT as you have seen
returns BIGINT and casts it into INT variable @X
So you are returning BIGINT SCOPE_IDENTITY and also concurrently casting it to INT and setting that result to @X.
Returning @X returns the INT result.
Just some interesting reading on the subject.