RE: inserting the max colum in the stored proc
- From: bruce barker <brucebarker@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 13 May 2008 11:23:01 -0700
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??
- Follow-Ups:
- RE: inserting the max colum in the stored proc
- From: iHavAQuestion
- RE: inserting the max colum in the stored proc
- References:
- inserting the max colum in the stored proc
- From: iHavAQuestion
- inserting the max colum in the stored proc
- Prev by Date: Re: Tracking user logins with Session_End or other
- Next by Date: .Net Winforms Control Deployment
- Previous by thread: Re: inserting the max colum in the stored proc
- Next by thread: RE: inserting the max colum in the stored proc
- Index(es):
Relevant Pages
|