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

Zerofill weekofyear function 1

Status
Not open for further replies.

aalnaif

Technical User
Jan 12, 2007
44
CA
I am using the built-in SQL weekofyear function, which returns a value between 1 and 52. My problem is I want the returned value to always be two digits (e.g. 01 instead of 1). Does anyone know how to do this?
 
cast it to VARCHAR, append it to the character '0', then take the last two characters using the RIGHT function

overlooking, of course, that RIGHT isn't an ANSI SQL function

:)

r937.com | rudy.ca
 
r937,

I'm not exactly sure what you mean by casting and appending. My code looks like this:

Select weekofyear(examination_date) as exam_week
from main_table

Would you be able to rewrite this code so that the exam_week column always contains two digits? Thank you.
 
Thanks r937, that's exactly what I was looking for! I see what you meant now in your first comment. That's very smart algorithm!
 
The keyword ALL <> *

INTO is not PART of the SELECT statement as described here.
 
Oops, disregard my posting above, wrong thread!

(This is a reason NOT to read multiple threads in different Firefox tabs...)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top