Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
kwacz23
Starting Member
44 Posts |
Posted - 2012-05-16 : 13:37:56
|
Hello I need help with that procedure. I would like to add autonumber to id_rezerwacji. this is the last part of that procedureExec add_reservation 3,4Decription parametrs3-it is a number for one activity4- it is client numberid_reservation here I want automatic numberdata-it is getdate-automaticcreate procedure @add_reservation@id_gym_activities int,@p_id int,@id_reservation int output,@data_reservation datetimeas begin insert rezerwacje (Id_konktetnych_zajec,P_id,id_rezerwacji,[Data rezerwacji],id_status)values (@id_konkretnych_zajec,@p_id,@id_rezerwacji,getdate(),'4')select @@IDENTITYend go |
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2012-05-16 : 13:52:56
|
If you make a column as id_reservation int identity(1,1) in you table, that will automatically increase by 1 everytime you insert in to it. Also, use select scope_identity() instead of @@identity.JimEveryday I learn something that somebody else already knew |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-05-16 : 20:15:18
|
quote: Originally posted by kwacz23 Hello I need help with that procedure. I would like to add autonumber to id_rezerwacji. this is the last part of that procedureExec add_reservation 3,4Decription parametrs3-it is a number for one activity4- it is client numberid_reservation here I want automatic numberdata-it is getdate-automaticcreate procedure @add_reservation@id_gym_activities int,@p_id int,@id_reservation int output,@data_reservation datetimeas begin insert rezerwacje (Id_konktetnych_zajec,P_id,id_rezerwacji,[Data rezerwacji],id_status)values (@id_konkretnych_zajec,@p_id,@id_rezerwacji,getdate(),'4')select @@IDENTITYend go
are you trying to retrive the generated id value by last statement?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|