Ludovic Aubert
Ludovic Aubert

Reputation: 10528

avoid explicit cast to float?

Can

SELECT CAST(2.083 AS float) AS c

be written in a more compact way ?

Something like

SELECT 2.083f AS c

?

Upvotes: 0

Views: 260

Answers (1)

Dan Guzman
Dan Guzman

Reputation: 46203

To avoid an explict CAST to float, specify a floating point constant expression:

--these both return float with precision 53
EXEC sp_describe_first_result_set N'SELECT CAST(2.083 AS float) AS c;';
EXEC sp_describe_first_result_set N'SELECT 2.083E0 AS c;';

--without scientific notation, the constant is interpreted as numeric(4,3)
EXEC sp_describe_first_result_set N'SELECT 2.083 AS c;';

Upvotes: 3

Related Questions