SQL For Returning Identity Of Newly Inserted Row Using CFQUERY

Hopefully I'll get off this sql kick some time soon, but another entry for my future reference.

For returning the identity of a newly inserted row in a database in a Coldfusion query:


<cfquery datasource="#application.datasource#" name="qryName">
Set Nocount on    
insert into myTable(myColumn1,myColumn2,myColumnN)
values(
<cfqueryparam cfsqltype="cf_sql_varchar" value="#myValue1#">,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#myValue2#">,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#myValue3#">
)
select IdentityInsert=@@identity
Set Nocount off
</cfquery>
<cfoutput>
#qryName.IdentityInsert#
</cfoutput>

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
BlogCFC was created by Raymond Camden. This blog is running version 5.9.1.001. Contact Blog Owner