Converting data type

  • In OLE DB Source Editor in SQL Command I have the following command

    SELECT LoanAddedDt

    FROM MyTable

    The date is in this format '2008-09-17' in SQL, in data viewer it's like this '9/17/2008'

    I want to change the format to this in 091708 when exporting to text file in SSIS

    I tried using this convert(varchar(8),replace(convert(varchar(8),[LoanAddedDt] ,1),'/','')) but when package runs I get the following error:

    [OLE DB Source [3114]] Error: There was an error with output column "LoanAddedDt" (3166) on output "OLE DB Source Output" (3124).

    The column status returned was: "The value could not be converted because of a potential loss of data.".

    Please help.

  • Try this:

    DECLARE @myDate DATE = '2008-09-17'

    SELECT REPLACE(CONVERT(CHAR(8),@myDate,10),'-','')

    Be careful, as you're introducing the Y2K bug all over again 🙂

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • Thanks. I already solved the problem by using the creating a custom function.

    y2k bug was a good job security!

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply