When you do SELECT @a
, you're returning a result set to some client (e.g. SQL Server Management Studio) that consists of a single column of type float
. It is then up to that tool to convert that float
into a string
using whatever options it deems appropriate in it's programming environment.
When you assign @a
to @b
, you force an implicit conversion from float
to varchar(10)
. SQL Server decides how to perform this conversion and then you send that data to the client tool in a second result set. It's likely that the client tools will do little or no manipulation because it's already, to some extent, a string.
So you've got two different things running conversions. SQL Server Management Studio1 will usually pick conversions similar to the ones that SQL Server itself would pick but it's by no means guaranteed, as you're observing with your test case here.
1Assumed as the usual starting point for people asking such questions. But equally valid for SQL Fiddle. The @b
conversion to a string was controlled by SQL Server. The @a
conversion was performed by some code within the SQL Fiddle application. This may be something built in to the language/framework SQL Fiddle is built in or some custom code. Doesn't matter. Key difference is that it's different code written by (probably) different authors with (potentially) different views on what makes a particular conversion the sensible default choice.