SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Create procedure
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

kwacz23
Starting Member

14 Posts

Posted - 05/16/2012 :  13:37:56  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

USA
2865 Posts

Posted - 05/16/2012 :  13:52:56  Show Profile  Reply with Quote
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

India
47023 Posts

Posted - 05/16/2012 :  20:15:18  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000