Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Having identity crisis!
Message
From
30/09/1999 13:32:43
 
 
To
30/09/1999 12:41:53
Bob Lucas
The WordWare Agency
Alberta, Canada
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00270941
Message ID:
00271207
Views:
23
Bob, et al:

This solution seems to give the desired result. I'm impressed with the willingness of everyone to work through this issue for me.

Thanks to all!
Tom.

>There is only one case when @@IDENTITY will not work. That is if your update causes a trigger to fire which also adds a record to a table that has an Identity column.
>
>@@IDENTITY will return the last Identity value created ON A CONNECTION.
>
>I know this is a big issue with SQL Server and I have had to deal with it in many ways.
>
>Once a new record is added, with an identity column as the primarykey, you are going to have to do something special to retrieve this value so you can populate the related child records. Here is what I do in the save method of my data classes
>
>TABLEUPDATE()
>
>If this.newrecord and this.identitykey
> *-- get the connection handle of the cursor that was just updated
> *-- this is necessary because you MUST query the same connection
> lnhandle = CURSORGETPROP("ConnectHandle")
> retval = SQLEXEC(lnhandle, "SELECT @@IDENTITY", sqlresult)
> SELECT sqlresult
> this.primarykey = EVALUATE(field(1))
>ENDIF

>>Anytime after the tableupdate() I can suspend, browse the remote view cursor, and see the value I need. But when I do a calculate() Select max() statement it holds a value for many iterations of the loop, increments it and holds it again for some time, and so on....
>>
>>Given the spec I have, this identity column is the only sure relational identifier I have available.
>>
>>Thanks!
>>Tom.
>>
>>>>Hi Tom ----
>>>>
>>>>Ian proposed @@IDENTITY, which is the optimal way of getting the latest ID, but that doesn't always work. Another way would be two open two connections to the table. Save on the first connection, then requery the table with the second connection and get the key that way.
>>>>
>>>
>>>John,
>>>
>>>How would you know which was the record ou had just added on the second connection? Would you need another key made up from the other fields?
>>>
>>>In what circumstances does @@IDENTITY not work? - I ask as its been ages now since I was lucky enough to do anything with SQL Server!
Previous
Reply
Map
View

Click here to load this message in the networking platform