There are several problems:
- You use
CONVERT
to convert a string to a string while you want a DATE
- You use
NVARCHAR
without a length (which is 1 by default) Bad habit to kick
- There is a comma missing after the date literal
- You are using
21
which is the format with a 2-digit-year Details here
Better was this
SELECT CONVERT(DATETIME, '2016-09-30', 121)
But even better was to avoid conversions at all.
In your case use Details here
- unseparated:
INSERT INTO #Test VALUES('20160930')
- ODBC (my favorite):
INSERT INTO #Test VALUES({d'2016-09-30'})
UPDATE
I cannot check this, no such versions installed, but I'm quite sure, that different default culture / language and implicit error correction leads to this behaviour...
On my SQL Server 2012 instance all of them work fine. The obvious format error (21 instead of 121) is corrected implicitly. The second obvious error (conversion to a 1-char-string) is corrected as well. Lower versions deal with this differently (probably).
If possible, try these lines on your servers...
SET LANGUAGE US_ENGLISH; --MDY
SELECT CONVERT(NVARCHAR, '2016-09-30', 21)
SET LANGUAGE GERMAN; --DMY
SELECT CONVERT(NVARCHAR, '2016-09-30', 21)
SET LANGUAGE JAPANESE; --YMD
SELECT CONVERT(NVARCHAR, '2016-09-30', 21)
The literal date format YYYY-MM-DD
, even as this is short ISO8601, is not sure in all situations. That's why one should use culture independant formats always...