I just inherited a stored procedure as part of a system for inserting a new user.
At the top, @user_id
is declared as INT OUTPUT
and at the bottom SET @user_id = @@IDENTITY
, which always returns zero for some reason. If I do:
select @@IDENTITY
...I get something around '1872040'
If I do:
SET @user_id = 187300
...I get:
Error converting data type int to smallint
I also get the same if I do:
SET @user_id = CAST(@@IDENITY as INT)...
It needs to be SET @user_id = CAST(@@IDENITY as TINYINT)
or just@user_id = @@IDENITY
for it to not give me errors. However, then it just returns null / 0. So, I was googling around and couldn't really find an answer, is there a better way to force the output param to not be tinyint? this is in ms sql.