Concatenate + Datetime conversion error

  • Hey folks,

    I'm writing a stored procedure that produces a .csv format (customers export this manually from the application)

    I have a requirement to concatenate some date fields, I can successfully convert from datetime to string and concatenate but not on the same line.

    Is this a possibility?

    Code Snippet:

    DECLARE @Dates AS TABLE(

    EmpNovarchar(6),

    Datevarchar(MAX),

    )

    INSERT INTO @Dates

    SELECTEmpNo,

    CONVERT(varchar(10), Date, 120)

    FROMTABLE1

    SELECT * from @Dates

    SELECTt.EmpNo,

    t.PLUID,

    COALESCE(d.Date + '; ', '') + d.Date AS Date

    FROMTABLE1 t

    INNER JOIN@Dates d

    ONt.EmpNo = d.EmpNo

  • Why are you concatenating the date with itself? What are you trying to do?

    There's no problem concatenating dates if you use CONVERT()

    DECLARE @SampleData TABLE(

    SomeDate date)

    INSERT INTO @SampleData

    VALUES(GETDATE()),(GETDATE() - 1),(GETDATE() - 2),(GETDATE() - 3),(GETDATE() - 4)

    SELECT CONVERT(char(10), SomeDate, 120) + ';' + CONVERT(char(10), SomeDate, 120)

    FROM @SampleData

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2

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

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