How do I cast Scope_Identity() to Int?
问题 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? 回答1: 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() 回答2: