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.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Create procedure

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 procedure

Exec add_reservation 3,4

Decription parametrs
3-it is a number for one activity
4- it is client number
id_reservation here I want automatic number
data-it is getdate-automatic


create procedure @add_reservation
@id_gym_activities int,@p_id int,@id_reservation int output,@data_reservation datetime
as
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 @@IDENTITY
end
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.


Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

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 procedure

Exec add_reservation 3,4

Decription parametrs
3-it is a number for one activity
4- it is client number
id_reservation here I want automatic number
data-it is getdate-automatic


create procedure @add_reservation
@id_gym_activities int,@p_id int,@id_reservation int output,@data_reservation datetime
as
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 @@IDENTITY
end
go


are you trying to retrive the generated id value by last statement?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -