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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Changing Date value

Author  Topic 

masond
Constraint Violating Yak Guru

447 Posts

Posted - 2013-12-06 : 03:38:23
Hi All
I am hoping you can help me

Aim – 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 01

Current results
FDMSAccountNo ACCOUNT-STATUS LAST-STATUS-CHG
878000000884 16 042312
878000000885 13 011212
878000000886 12 100712



Desired results
FDMSAccountNo ACCOUNT-STATUS LAST-STATUS-CHG Start_of_month
878000000884 16 23-04-12 01-04-12
878000000885 13 01-12-12 01-12-12
878000000886 12 10-07-12 01-07-12



My query is
SELECT [FDMSAccountNo]
,[ACCOUNT-STATUS],
[LAST-STATUS-CHG]
FROM [FDMS].[dbo].[stg_LMPAB501]
where FDMSAccountNo = '878000000884'

looking forward to your help

Regards
D

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]
Go to Top of Page

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
Go to Top of Page
   

- Advertisement -