SQLTeam.com | Weblogs | Forums

Behavior of CONVERT



Hello, I put this in the Corral as it is not really a question...
I was concatenating to create a unique ID by adding a DATETIME value to a given CHAR value. This went well. I then wanted to add some archive data which used DATE and TIME. Well I was surprised when during a test the values were okay even though I thought I would need more conversions/manipulations.

CREATE TABLE #myTemp (RecDate DATE, RecTime TIME);

-- style 120 --- yyyy-mm-dd hh:mi:ss(24h)
SELECT P.RecDate, CONVERT(VARCHAR(20), P.RecDate, 120), P.RecTime, CONVERT(VARCHAR(20), P.RecTime, 120), CONVERT(VARCHAR(20), P.RecDate, 120) + ' ' + CONVERT(VARCHAR(20), P.RecTime, 120) 
FROM #myTemp P; 

DROP TABLE #myTemp; 

I though the time would add a date and the date add a time. Note I used code from converting the DATETIME and had not changed it yet. At this point I found I did not need to make changes to the code.

Just thought I would see if anyone else had similar "it was less complicated than I thought".