Home Forums SQL Server 2008 SQL Server 2008 - General Help with doing “Cast the decimal as string, parse into the format specified, and then cast back into datetime”? RE: Help with doing “Cast the decimal as string, parse into the format specified, and then cast back into datetime”?

  • ********This is the DDL***************

    USE [stgFACTS]

    GO

    SET ANSI_NULLS ON

    GO

    SET QUOTED_IDENTIFIER ON

    GO

    SET ANSI_PADDING ON

    GO

    CREATE TABLE [dbo].[I353_SalesOrder](

    [I353_DATE_TRANSACTION] [decimal](8, 0) NULL,

    [I353_TIME_TRANSACTION] [decimal](6, 0) NULL,

    CONSTRAINT [PK_I353_SalesOrder] PRIMARY KEY CLUSTERED

    (

    [I353 _ITEM_NBR] ASC,

    [I353 _SHIP_SUFFIX] ASC,

    [I350_SALE_ORDER_NBR] ASC,

    [I351 _ITEM_NBR] ASC,

    [IDMS_UPDATE_TIME] ASC

    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

    ) ON [PRIMARY]

    GO

    SET ANSI_PADDING OFF

    GO

    Insert statements

    INSERT INTO [stgFACTS].[dbo].[I353_SalesOrder]

    (

    ,[I353_DATE_TRANSACTION]

    ,[I353_TIME_TRANSACTION]

    VALUES

    (,<I353_DATE_TRANSACTION, decimal(8,0),>

    ,<I353_TIME_TRANSACTION, decimal(6,0),>

    ,<ACTIVE_FLAG, nvarchar(1),>)

    GO

    ******************************************************************

    Output looks like (its in YYYYMMDD order I want it in MM/DD/YYYY order)

    20120910

    20120910

    20120913

    20120913

    20120917

    20120917

    20120925

    20120926

    20121001

    20121001

    20121003

    20121004

    20121004

    20121004

    20121008

    20121010

    20121029

    20120917

    20030515

    20030604

    20120806

    20120806

    20120806

    20120827

    20120904

    20120904

    20120904

    20120905

    20120906

    20120924

    20120924

    20120924

    20120925

    20120925

    20121008

    20121008

    20121008

    20121008

    20121015

    20121024

    0

    20120912

    20120912

    20120912

    20120914

    20120914

    20120914

    20120914

    20120914

    20120914

    20031119

    20040112

    20040113

    0

    20120920

    20120920

    20121002

    20121005

    20121017

    20121018

    20121018

    20121026

    20121102

    20030909

    20120914

    20121011

    20030604

    20031103

    20120918

    20121015

    0

    20121018

    0

    20121009

    20121009