I have been reading Robert Vieira's book 'Professional SQL Server 2000 Programming' and on page 45 he discuses data type conversions and presents a chart showing the allowable conversions and whether they are explicit or implicit conversions.
The chart states that the datetime and smalldatetime data types will implicitly convert to char, varchar, nchar and nvarchar data types, however the example that follows the chart demonstrates that the string "Today's date is " can not be concatenated with the return value of the GETDATE() function unless it is explicitly converted to a varchar data type.
Quote:
quote:[u]From pages 45-46 of Pro SQL Server 2000 Programming</u>
SELECT 'Today''s date is ' + GETDATE()
The problem is that this statement would yield the following result
Server: Msg 241, Level 16, State 1, Line 1
Syntax error converting datetime from character string.
Not exactly what we were after, is it? Now let's try it with the CONVERT() function:
SELECT "Today's date is " + CONVERT(varchar(12), GETDATE(),101)
This yields something like:
--------------------------
Today's date is 01/01/2000
(1 row(s) affected)
|
As far as I can see this appears to be in contradiction to the data type conversion chart. I have run the example and an error is generated if I do not explicitly convert the data type as would be expected.
Am I reading the chart wrong or is the chart wrong?
Regards
Owain Williams