Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

stored procedure concatenation problem

Status
Not open for further replies.

beaniebear

Programmer
Sep 14, 2001
93
GB
When I add a new member of staff to a table I require a reference to be added to the reference field which is year/nextrefence ie 2009/0001. Only the year is being displayed. Could you please let me know where I am going wrong? Or if there is a better way to do what I' trying to do?

Insert Into Staff(LastName) values ('smith')

declare @ID int
declare @Counter int
declare @NextRef char(9)
declare @Year int

set @ID = scope_identity()

update NextReference set NextReference.Counter=NextReference.Counter +1 where NextReferenceID=1
select @Counter=counter from nextreference where NextReferenceID=1
set @Year=year(getdate())

set @NextRef = cast(@year as char) + '/' + cast(@Counter as char)

Update Staff set Reference = @NextRef where BookingID=@ID
 
select @NextRef =(cast(@year as char) + '/' + cast(@Counter as char))

changed this to

select @NextRef =(cast(@year as char(4)) + '/' + cast(@Counter as char(4)))

now it works, phew!

Still be interested to hear if there is a better solution to this? Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top