Click here to Skip to main content
15,070,282 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello all

i have a table with some colom
id, firstname, lastname
i want to create store procedure when insert in this table
id automatic generate like this L110000001BCA , L110000002BCA , L110000003BCA

thx everyone
Posted

   
Comments
gunkrr 6-Oct-11 2:25am
   
thx 4 ur attention
let test this

SQL
Create Procedure InsData @FirstName varchar(50), @LastName varchar(50)
As
Begin
    Declare @id int
    Select @id=max(CAST(SUBSTRING(id,2,9) as Int)) from TableName
    Insert into TableName(id,firstname,lastname)
    Values('L'+CAST((@id+1) as varchar(10)+'BCA',@FirstName,@LastName)
End
   
v2
Comments
gunkrr 6-Oct-11 2:35am
   
ERRor in

Msg 156, Level 15, State 1, Procedure sp_generateid2, Line 18
Incorrect syntax near the keyword 'from'.
Msg 102, Level 15, State 1, Procedure sp_generateid2, Line 20
Incorrect syntax near ','.


why thats??
gunkrr 6-Oct-11 2:45am
   
i know that
thx
why the output is L112BCA, not L110000002BCA ???

can anybody help me
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900