Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 setting the default of one column equal to the value of another

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-01-23 : 18:30:44
Moshe writes "I want to insert the value of an identity field in a standard field when a
new record is created, for example,

I add a new record, and I insert the value into various fields. There is a field
called "rank". I want the value of the field "object_id" (indentity) to be
in the field "rank". My guess is that when I add a new item, the indentiy
field doesn't get its value until I update. I don't know much about stored
procedured, so that avenue hasn't been explored, I know of the @@indentity
variable. Here is my code,

oRs.AddNew
oRs("object_label") = cLabel
oRs("object_target") = cTarget

If parentid = "" Then
oRs("parent_id") = 0
Else
oRs("parent_id") = parentid
End If
oRs("rank") = oRs("object_id")
oRs.Update

The above is part of an updateBatch operation, and is just one iteration.

FYI: The object_id is the permanent identifier for the record but the rank
can be changed by the user, I use it as a basis for a sort when I retrieve a recordset.

Thanks."
   

- Advertisement -