Hay 3 métodos diferentes dependiendo de cuál sea mi requerimiento y qué versión estoy usando.
Estos son los métodos ...
1) Usando Convertir
DECLARE @DateTime DATETIME = GETDATE();
SELECT
CONVERT(NVARCHAR, @DateTime,120) AS 'myDateTime'
,CONVERT(NVARCHAR(10), @DateTime, 120) AS 'myDate'
,RIGHT(CONVERT(NVARCHAR, @DateTime, 120),8) AS 'myTime'
2) Uso de Cast (SQL Server 2008 y posteriores)
SELECT
CAST(@DateTime AS DATETIME2) AS 'myDateTime'
,CAST(@DateTime AS DATETIME2(3)) AS 'myDateTimeWithPrecision'
,CAST(@DateTime AS DATE) AS 'myDate'
,CAST(@DateTime AS TIME) AS 'myTime'
,CAST(@DateTime AS TIME(3)) AS 'myTimeWithPrecision'
3) Uso del tipo de datos de caracteres de longitud fija
DECLARE @myDateTime NVARCHAR(20) = CONVERT(NVARCHAR, @DateTime, 120);
DECLARE @myDate NVARCHAR(10) = CONVERT(NVARCHAR, @DateTime, 120);
SELECT
@myDateTime AS 'myDateTime'
,@myDate AS 'myDate'