SCOPE_IDENTITY () return value

  • Thread starter Thread starter RA
  • Start date Start date
R

RA

I have an identity column defined as int in sql 2000.
I use SCPOE_IDENTITY () to get the new inserted column id. The problem is
that the object returned from the ExecuteScalar is of type Decimal? why is
that happens?

Thanks,
Ronen
 
Hi Ronen,

Why is this a problem?
It is an universal format for an identity field.
 
But the culumnid is defined as integer in the sql database, why is the
scope_identity returns decimal value?

Ronen
 
Since SCOPE_IDENTITY () is a function that has a single declaration and
identity fields can be decimals too, it is normal that it uses the greates
denominator (you can convert from int to decimal but not viceversa).
 
Then in that case I would use the following:
Insert (...); Select customerid from table where (customerid =
scope_indentity())

In this case I will get an int back, am I correct on that?

Ronen
 
Nope,

select cast(scope_identity() as int)
should be correct.

--
Miha Markic - DXSquad/RightHand .NET consulting & software development
miha at rthand com

Developer Express newsgroups are for peer-to-peer support.
For direct support from Developer Express, write to (e-mail address removed)
Bug reports should be directed to: (e-mail address removed)
Due to newsgroup guidelines, DX-Squad will not answer anonymous postings.
 
Back
Top