So Scope_Identity() returns an ?-Byte Numeric Type in SQL Server.
That is not awesome.
Is there a safe way to cast it to an int in a select query so we don't have to manage every whim of SQL Server in our ODBC Wrapper?
If the source column to which the identity belongs is an Integer, there's no need to cast it. The following works just fine assuming the identity column is an Integer to begin with or it fits inside an "Int".
DECLARE @NewIdent Int SET @NewIdent = SCOPE_IDENTITY()
SELECT CAST( bigintcolumn AS int )
(Provided you know it will fit into a 32bit integer)
Just cast this like:
select CAST(SCOPE_IDENTITY() as int)
And your data Layer: