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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Month/Year Expression 1

Status
Not open for further replies.

IanWaterman

Programmer
Jun 26, 2002
3,511
GB
From my query I have summary data grouped by two numeric fields Month and year.

I want to produce a chart by month and would like to concatenate the Month and year together and pad the single digit months with a zero so that they sort correctly.

ie

01/2011, 02/2011,..... 10/2011 etc

What is the syntax to do this please, when I look at the field properties for Month I see

=Fields!Mth.Value

I could do this in query
cast(Year as varchar(4))&'/'&cast(Mth as varchar(2))
But I do not know syntax for padding Mth with leading zeros

Thank you

Ian
 
To pad with a leading zero, you do something like this. Note that depending on the database you are using, you might use + instead of &.

Code:
cast(Year as varchar(4)) + '/' + RIGHT('0' + cast(Mth as varchar(2)), 2)
 
Thanks.

I am using SQL server but also use Oracle so got my syntax mixed up, had to use + as you suggested.

Ian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top