I am moving some data and I need to come up with a TSQL statement to convert dates currently in a datetime field to another database field with the varchar MM/yy format.
This statement needs to work on both SQL Server 2k5 and also SQL Compact Edition 3.5 – so the answer needs to be ‘set’ based and not include cursors etc that are not supported in SQLCE.
relying on the type, i.e. ‘101’ could be dangerous if you ever run on a non-US database server, as the mm and dd would be switched around. Probably the same with using type ‘3’. As long as you know the language of the server will always be the same, those methods are the easiest.
Using datepart is probably more reliable, but if you want say 03/08 instead of 3/08, you have to make sure to prefix the month with a ‘0’, so