Evaluation time for functions SQL2005 / SQL2000

  • I have a database that has recently migrated from SQL 2000 to SQL2005. I have a problem with the evaluation of a function which did not cause problems in SQL 2000 but does in 2005.

    The function ( getNextID() ) generates a new ID value for a table. There is no Identity column defined on that table, its just an int column and this function is used to generate the next sequential value (... I inherited this database, I don't know why they didn't just define an Identity column).

    The problem arises when inserting more than one new row with code like this:

    INSERT INTO Project (ProjectID, [Description], [Manager])

    SELECT dbo.GetNextID(), [ProjectDescription], [ProjectManager]

    FROM tmpImportTable_Project

    In SQL 2000 this works correctly when you are inserting > 1 new row. That is, the insert statement correctly generates a sequential value for each new row.

    In SQl 2005 however, the function seems to be evaluated for all new rows prior to any rows being inserted, and not evaluated after each and every new row is inserted. So it doesn't generate a sequential value for each new row, it generates the same value for each and every row. Any inserts then fail on the second row because of a PK violation.

    I can write a bit of script to generate the required sequential IDs; thats not a problem. But I wondered if anyone had met this problem before and if they had a resolution for it?

    Is there perhaps a global setting in 2005 that would affect the evaluation-time of functions?

    Kind regards,

    Eric.

Viewing 0 posts

You must be logged in to reply to this topic. Login to reply