Should work just fine, but you should set the nocount. Hope that helps
<cfquery name="personInsertQuery" datasource="mydb" >
set nocount on
insert into
person (firstName,lastName)
values
(
<cfqueryparam cfsqltype="CF_SQL_VARCHAR"
value="#firstName#">,
<cfqueryparam cfsqltype="CF_SQL_VARCHAR"
value="#lastName#">
);
set nocount off
select @@identity as personId;
</cfquery>
<cfset personId = personInsertQuery.personId>
Doug B.
----- Original Message -----
From: "Kevan Stannard" <[EMAIL PROTECTED]>
To: "CF-Talk" <[email protected]>
Sent: Wednesday, January 17, 2007 6:58 PM
Subject: Getting auto generated id after insert in MSSQL
> Hi everyone
>
> Can anyone advise if this is the best way to get the auto generated id
from
> MSSQL after an insert? Is it multiuser safe?
>
> <cfquery name="personInsertQuery" datasource="mydb" >
> insert into
> person (firstName,lastName)
> values
> (
> <cfqueryparam cfsqltype="CF_SQL_VARCHAR"
> value="#firstName#">,
> <cfqueryparam cfsqltype="CF_SQL_VARCHAR"
> value="#lastName#">
> );
>
> select @@identity as personId;
> </cfquery>
>
> <cfset personId = personInsertQuery.personId>
>
> Thanks
>
> Kevan
>
>
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Upgrade to Adobe ColdFusion MX7
Experience Flex 2 & MX7 integration & create powerful cross-platform RIAs
http:http://ad.doubleclick.net/clk;56760587;14748456;a?http://www.adobe.com/products/coldfusion/flex2/?sdid=LVNU
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:266844
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4