Search code examples
sqlsql-servervba

why does SELECT SCOPE_IDENTITY() return null?


in what case does SELECT SCOPE_IDENTITY() return null?

i am doing this:

Set rs = cn.Execute("SELECT SCOPE_IDENTITY()", , adCmdText)
capture_id = rs.Fields(0)

and i getting capture_id=null


Solution

  • According to MSDN, "The SCOPE_IDENTITY() function will return the null value if the function is invoked before any INSERT statements into an identity column occur in the scope."