Thursday, February 16, 2012

Add a number to string. (conversion problem)

Lets say I have a table named Projects with the data below.
Y07001
Y07002
Y07003
Y07010
Y07011
I want to pick up the last 3 numbers and add a one to it so.

Declare @.Countas varchar(3)SELECTTop 1 @.Count=Right(Project, 3)+1FROM ProjectsOrderby IDdesc

SELECT @.Count

This is what I am using. It picks up the last entry, add a one to it and gives me 12 in return. What i want is 012, not 12

What you want is probably this?

SELECT

RIGHT('000'+Convert(varchar,@.Count),3)

No comments:

Post a Comment