SCOPE_IDENTITY () return value

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
 
M

Miha Markic

Hi Ronen,

Why is this a problem?
It is an universal format for an identity field.
 
R

RA

But the culumnid is defined as integer in the sql database, why is the
scope_identity returns decimal value?

Ronen
 
M

Miha Markic

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).
 
R

RA

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
 
M

Miha Markic

Yup.
I think you might also Cast (SCOPE_IDENTITY as Int) - should be faster.
 
R

RA

(Select SCOPE_IDENTITY () as Int) is that the correct syntext to sql server
2k?
Ronen
 
M

Miha Markic

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top