in reply to Re: mssql query
in thread mssql query

I'm not trying this, but I'd use a semicolon between the first and the second SQL statement.

Anyway, a dirty and bad looking solution is to have a separate statement MAX() the value of the identity column (that will likely be a unique key, right?) so you get the last inserted value with no table or key scan, and the disk page will very likely be in RAM as you just used it. It's quite fast, if you can afford the two separate database statements. Of course demerphq solutiuon is better. :-)

Replies are listed 'Best First'.
Re: Re: Re: mssql query
by mpeppler (Vicar) on Dec 01, 2003 at 16:32 UTC
    I'd use a semicolon between the first and the second SQL statement
    No semicolon needed between statements with MS-SQL, and in fact the semi-colon would be a syntax error with Sybase.
    ...a dirty and bad looking solution is to have a separate statement MAX() the value of the identity...
    Unless you use a transaction around the insert and the select max() (which effectively single threads inserts) then there is no guarantee that the max() will be the value that you just inserted (unless of course you know that you are the only process inserting data to that particular table).

    Michael