> I know this came up last week or so, but I believe the answer came for a
> mySQL database. I need a way in MS SQL to get the last inserted record
> via CF. I have a query inserting a row into the table with an
> auto-increment ID. I need to insert that ID into a separate table in
> another query so I first need to find out what ID it got assigned. I've
> got it all wrapped in <cftransaction> but I'm not sure if max(id) is the
> best way to get the ID, because if rows get deleted, won't SQL
> automatically assign those values to new rows at some point, therefore
> negating the max() idea?
John, if you have no intention of ever moving off of MSSQL you can use
the variable @@identity to get the last inserted it. For example:
<cfquery name="idtest" ...>
set nocount on
insert into my_table (
test
) values (
'hi there'
)
select @@identity as newid
set nocount off
</cfquery>
<cfdump var="#idtest#">
If you think you might move off of MSSQL I wouldnt do that.
--
Rob <[EMAIL PROTECTED]>
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

