Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

execute select statement

Status
Not open for further replies.

hkung

Programmer
Jan 9, 2001
19
0
0
MY
Hi all,

i'm using sql server 2000 and my vb program needs to execute the select statement below in order to get the maximum value of identity column in my table :

select @@identity from table1

i did the following :

sqlstr = "select @@identity from table1"
set rs = dbconn.execute (sqlstr)

however, it doesn't seem to work out the same result as i run the query in sql server Query Analyser. I believe it's because of the @@...anyone has any ideas how could i solve this? Thanks in advance!


 
Hi,

It is because you are not using the same connection. @@IDENTITY follwes the connection. E.I. you have to add records with the same connection as you retrieve the @@IDENTITY.

As far as I know 'SELECT @@IDENTITY FROM tblMyTable' does not make sence (even thought it works). The correct synax is simply 'SELECT @@IDENTITY' as @@IDENTITY always will return a value from the last insert no matter which table you insert into.

Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top