15 pts.
Q:
Concatenation
I am using "substring(concat('00'...." within my SQL select for a date query. However, the date 10 and higher is being overridden with "0". How do I prevent this from happening?
ASKED: Jun 9 2009  6:55 PM GMT
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
1945 pts.
A:
 RATE THIS ANSWER
0
Click to Vote:
  •   0
  •  0
  • Bookmark and Share
Please show the entire SQL statement. It is impossible to know what you are doing by looking at the fragment. Table definition info would also help.



KCCrosser - If you are trying to ensure the month and day are 2-digits with leading zeros, the easy way is to use:

set @monthstring = right('0' + convert(varchar(2),month(<date>)),2)
set @daystring = right('0' + convert(varchar(2),day(<date>)),2)

I.e. prepend a '0' character on the current string, then take the rightmost two characters. For values like '10', this creates '010', then take the rightmost 2 to get '10'. For digits 1-9, it returns '01' thru '09'.
Last Answered: Jun 10 2009  11:35 PM GMT by Kccrosser   1945 pts.
Latest Contributors: Dmenke38   185 pts.
Discuss This Answer:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _