Link to home
Start Free TrialLog in
Avatar of jglazer63
jglazer63

asked on

cannot get a value from scope_identity after insert

In ASp i am doing this:

set objrs=objconn.execute("insert into cart (title) values ('something');select SCOPE_IDENTITY() as id;")

When I check objrs("ID") it returns blank.  Nothing.  This works fine access but not in SQL 2000.  I find that it seems to have something to do with it being in the second line of the SQL.  if I replace the scope_identity() with max(cartid) i get the same thing.  So the second line is not returning a value.

Running this in the query analyzer DOES return the value as expected.

Any ideas?
Avatar of saoirse1916
saoirse1916
Flag of United States of America image

Have you tried running this query as a stored procedure?  I seem to remember running into this a while back and setting up an SP fixed it.
Avatar of jglazer63
jglazer63

ASKER

I do not want to do this as a stored procedure.  I want to do this entirely with the ADO execute.  It needs to be very generic.
ASKER CERTIFIED SOLUTION
Avatar of BrandonGalderisi
BrandonGalderisi
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Also, although I know you say you don't want a proc, but a proc is the BEST thing for DB processing.
That's it -- SET NOCOUNT ON...I knew there was something I was missing.  Brandon's right on the money.
Perfect.  You got it.  Thanks!