|
-
Dec 6th, 2000, 09:27 AM
#1
Thread Starter
New Member
Good morning,
I am having the following problem:
I need to add new records on a SQL Server and then get the @@identity to pass to a related table. The problem is that the client is not letting me used stored procedures. How can I pick up the identity in ASP?
Thanx!
Mordechai Boehm
LaserStreak Consulting
www.LaserStreak.com
-
Dec 6th, 2000, 09:54 AM
#2
Frenzied Member
The only things I could suggest is to try:
select max(identidycolumnname) from table
If your using an identity column in the table that is auto-populated by SQL Server, you should 99% of the time get the correct one. Only if someone else saved a record in the time it takes to execute the query after the insert, would the data be wrong.
Another thing to try would be to use a select with a where clause that includes the criteria you just wrote to the table to get just the identity column returned. That would work unless there is more than one match, then you could use the higher of the two. (Again, there is a small margin of error here- like if someone else saves similar data around the same time or just after)
oOOo--oOOo
__ /\/\onte96
oOOo--oOOo
Senior Programmer/Analyst
MCP
[email protected]
[email protected]
Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..
-
Dec 6th, 2000, 10:03 AM
#3
Fanatic Member
Hi mobo10
I've just given this a try and it seems to work fine
Set rs = Server.CreateObject("adodb.recordset")
objCon.execute "Insert into tblTest(field1) Values('32323')"
RS.Open "SELECT @@IDENTITY",objCon,adOpenStatic
Response.Write rs(0)
Yeah, well I'm gonna build my own lunar space lander! With blackjack aaaaannd Hookers! Actually, forget the space lander, and the blackjack. Ahhhh forget the whole thing!
-
Dec 7th, 2000, 07:46 AM
#4
Addicted Member
This is a little slower, but its fool proof, and it DOES work with cookies turned of before anyone says that.
Insert into SQL_Table (data, tempfield) Values('"&&"', '"&session.sessionid&"')
Select ID_Field from SQL_TABLE WHERE tempfield = '"&session.sessionid&"'
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|