March 31, 2015 at 7:00 am
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
March 31, 2015 at 10:20 am
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
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply