RE: inserting the max colum in the stored proc



Inseret into table1 (
col1
col2
col3
)
Values (
(select max(col1) from table1
@Var2
@Var3
)

of course if two inserts happen at the same time, they will get the same
result. you can set the isolation level to serializable (at a big performance
cost), or if col1 has a unique index, catch the duplicate key error and
resubmit on the failed insert (a better option)

a better option is to use the identity constaint, at let sqlserver assign
the max.

-- bruce (sqlwork.com)


"iHavAQuestion" wrote:

I have stored procedure
Create Stored Procedure Name
(
@Var1
@Var2
@Var3
)
Inseret into table1
(
Col1
col2
col3
)
Values
(
@Var1
@Var2
@Var3
)

But in col1 i need to insert select max(col) from tablename, which is in the
same database.

how do I do that??
.



Relevant Pages

  • RE: inserting the max colum in the stored proc
    ... Create Stored Procedure Name ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Subquery
    ... probably want a query that selects from, ... But if there is no row in table1 for a particular company_id, ... no col1 value, either. ... result using a left outer join. ...
    (microsoft.public.sqlserver.programming)
  • Re: simple stored procedure
    ... CREATE TABLE table1 (col1 int) ... INSERT INTO table1 VALUES ... CREATE TABLE table2 ...
    (microsoft.public.inetserver.asp.db)
  • Re: inserting the max colum in the stored proc
    ... Create Stored Procedure Name ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Misnomers in the COBOL standard
    ... I always liked it that COBOL nearly always worked left to right: MOVE VAR1 ... TO VAR2, ADD 1 to VAR3, etc. ... DIVIDE A BY B would have broken this which is why it requires GIVING. ...
    (comp.lang.cobol)