Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 321
Peter Turner Avatar asked Jun 16 '09 14:06

Peter Turner


2 Answers

SELECT CAST( bigintcolumn AS int )

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

like image 182
Mitch Wheat Avatar answered Sep 20 '22 09:09

Mitch Wheat


Just cast this like:

select CAST(SCOPE_IDENTITY() as int)

And your data Layer:

reader.GetInt32(0);
like image 44
user8020064 Avatar answered Sep 18 '22 09:09

user8020064