views:

305

answers:

2

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?

+5  A: 
SELECT CAST( bigintcolumn AS int )

(Provided you know it will fit into a 32bit integer)

Mitch Wheat
That's what I thought, I'm not sure why it doesn't work though. T'was returning 0.
Peter Turner
+6  A: 

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()
Jose Basilio