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 |
masond
Constraint Violating Yak Guru
447 Posts |
Posted - 2013-12-06 : 03:38:23
|
Hi AllI am hoping you can help meAim – Currently i have column “[LAST-STATUS-CHG]” in the following date format “042312” i need this date format to be changed into “23-04-12”.Also i would like an additional column created called “Start of month” this column should look at “[LAST-STATUS-CHG]” and what ever the day is in the defauly it to 01Current results FDMSAccountNo ACCOUNT-STATUS LAST-STATUS-CHG878000000884 16 042312878000000885 13 011212878000000886 12 100712Desired results FDMSAccountNo ACCOUNT-STATUS LAST-STATUS-CHG Start_of_month878000000884 16 23-04-12 01-04-12878000000885 13 01-12-12 01-12-12878000000886 12 10-07-12 01-07-12My query isSELECT [FDMSAccountNo],[ACCOUNT-STATUS],[LAST-STATUS-CHG]FROM [FDMS].[dbo].[stg_LMPAB501]where FDMSAccountNo = '878000000884'looking forward to your help RegardsD |
|
Kristen
Test
22859 Posts |
Posted - 2013-12-06 : 03:45:35
|
[code]SELECT [FDMSAccountNo],[ACCOUNT-STATUS],[NEW-LAST-STATUS-CHG] = SUBSTRING([LAST-STATUS-CHG], 3, 2) + '-' + LEFT([LAST-STATUS-CHG], 2) + '-' + RIGHT([LAST-STATUS-CHG], 2)FROM [FDMS].[dbo].[stg_LMPAB501]where FDMSAccountNo = '878000000884'[/code] |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2013-12-06 : 04:44:05
|
Hello and welcome back, Kristen! Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA |
|
|
|
|
|
|
|