Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Chadzuk
Starting Member
6 Posts |
Posted - 2007-04-27 : 18:16:12
|
Hello all, I was wondering if someone might be able to assist me with how to code something. I need to concatenate a date into a YYYYMMDD format however from the database I am pulling it from the year, month, and day are all in there own fields. This isn't difficult to deal with however the catch is if the month is 1 character I need to add a 0 to the front of it, same with the day. The CASE statement to do this has me confused. For example.Year = 2007Month = 2Day = 8I need to take these out of the seperate fields and make it look like "20070208" in a new field. If the month or day is 2 characters I don't need to add the zero to the front. I also have to do a CAST on each field when combining them or it will add them together instead of concatenating them. This is the first step to a complex statement but I think if I can get this I can figure the other part out. Any help anyone can give would be wonderful.Thank you in advance. |
|
dinakar
Master Smack Fu Yak Hacker
2507 Posts |
Posted - 2007-04-27 : 18:25:41
|
You mean select '2007' + RIGHT(('00' + '2'),2) + right(('00' + '8'),2) Dinakar NethiSQL Server MVP************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/ |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
|
|
|