CONVERT
is SQL Server specific.CAST
is ANSI.SELECT [Name], [ListPrice]
FROM [Production].[Product]
WHERE CONVERT(INT, [ListPrice]) LIKE '3%';
-- CAST([ListPrice] AS INT) LIKE '3%'
DECLARE @Date DATETIME = '2000-01-01 13:30:30'
SELECT
@Date 'Original',
CONVERT(VARCHAR, @Date, 101) 'US Format', -- mm/dd/yyyy
CONVERT(VARCHAR, @Date, 23) 'ISO 8601 Date', -- yyyy-mm-dd
CONVERT(VARCHAR, @Date, 112) 'ISO 8601 Date, No Dash', -- yyyymmdd
CONVERT(VARCHAR, @Date, 126) 'ISO 8601 DateTime' -- yyyy-mm-ddThh:mi:ss.mmm
CONVERT(VARCHAR, @Date, 127) 'ISO 8601 DateTime & Time Zone Z.' -- yyyy-mm-ddThh:mi:ss.mmmZ
binary
/varbinary
to or from Unicode data types.
SELECT
CONVERT(VARBINARY, 'Test', 0), -- 0x54657374
CONVERT(VARCHAR, 0x54657374, 0), -- Test
CONVERT(NVARCHAR, 0x41), -- A
CONVERT(VARBINARY, 'A'), -- 0x41
CONVERT(VARBINARY, CONVERT(NVARCHAR, 0x41)) -- 0x4100
datetimeoffset
and the character types char
, varchar
, nchar
, and nvarchar
the converted time zone offset part should always be double digits for both HH and MM for example, -08:00.https://s3-us-west-2.amazonaws.com/secure.notion-static.com/fb4b9024-7d73-4f6e-bd40-d197d2498788/Untitled