I am using SQL Server 2000. I am pulling year, month and count, but the query is returning value without leading zero (for Jan, return is 1 instead of 01)
I need to concatenate several values to form a key that will be used for calling up a record. The key is based on a type, year and counter, where the counter increments by type and month and resets with new month. I added 100 to counter the dropped zero, but when I convert datatype and use the RIGHT function, the zero is still dropped.
I have the following code:
Select msnIdentification, SequenceYear, SequenceMonth = (100 + SequenceMonth),
SequenceCount = (100 + SequenceCount), msnIdentification
+ convert(varchar(2), right(SequenceYear,2)) +
convert(varchar(2), right(SequenceMonth,2)) +
convert(varchar(3), right(SequenceCount,2))
from logSequenceCounter
go
which produces the following results:
HW 2007 103 101 HW0731
HW 2007 104 101 HW0741
IW 2007 101 102 IW0712
CW 2007 102 102 CW0722
IW 2007 103 103 IW0733
HW 2007 101 104 HW0714
HW 2007 105 106 HW0756
BW 2007 103 107 BW0737
IW 2007 104 110 IW07410
CW 2007 101 122 CW07122
IW 2007 102 122 IW07222
CW 2007 105 129 CW07529
What I am looking for is:
HW 2007 103 101 HW070301
HW 2007 104 101 HW070401
IW 2007 101 102 IW070102
CW 2007 102 102 CW070202
IW 2007 103 103 IW070303
HW 2007 101 104 HW070104
HW 2007 105 106 HW070506
BW 2007 103 107 BW070307
IW 2007 104 110 IW070410
CW 2007 101 122 CW070122
IW 2007 102 122 IW070222
CW 2007 105 129 CW070529
Thanks... I know the solution is simple, but I am not an application programmer, and simple would not apply with my experience.
![[noevil] [noevil] [noevil]](/data/assets/smilies/noevil.gif)
Glen Braden
I need to concatenate several values to form a key that will be used for calling up a record. The key is based on a type, year and counter, where the counter increments by type and month and resets with new month. I added 100 to counter the dropped zero, but when I convert datatype and use the RIGHT function, the zero is still dropped.
I have the following code:
Select msnIdentification, SequenceYear, SequenceMonth = (100 + SequenceMonth),
SequenceCount = (100 + SequenceCount), msnIdentification
+ convert(varchar(2), right(SequenceYear,2)) +
convert(varchar(2), right(SequenceMonth,2)) +
convert(varchar(3), right(SequenceCount,2))
from logSequenceCounter
go
which produces the following results:
HW 2007 103 101 HW0731
HW 2007 104 101 HW0741
IW 2007 101 102 IW0712
CW 2007 102 102 CW0722
IW 2007 103 103 IW0733
HW 2007 101 104 HW0714
HW 2007 105 106 HW0756
BW 2007 103 107 BW0737
IW 2007 104 110 IW07410
CW 2007 101 122 CW07122
IW 2007 102 122 IW07222
CW 2007 105 129 CW07529
What I am looking for is:
HW 2007 103 101 HW070301
HW 2007 104 101 HW070401
IW 2007 101 102 IW070102
CW 2007 102 102 CW070202
IW 2007 103 103 IW070303
HW 2007 101 104 HW070104
HW 2007 105 106 HW070506
BW 2007 103 107 BW070307
IW 2007 104 110 IW070410
CW 2007 101 122 CW070122
IW 2007 102 122 IW070222
CW 2007 105 129 CW070529
Thanks... I know the solution is simple, but I am not an application programmer, and simple would not apply with my experience.
![[noevil] [noevil] [noevil]](/data/assets/smilies/noevil.gif)
Glen Braden