Why SELECT 28F3 Returns 28: Float Literals and Hidden Aliases

One letter changes whether a short SELECT names a column or scales a number. Understanding float literals and optional aliases explains why SELECT 28F3 returns 28 while SELECT 28E3 represents 28000.

Sausage links on a red hook, one missed twist leaving two sausages joined into one long one

Separate the Value From Its Output Name

The expression 28F3 looks like one unusual number, but T-SQL reads it as the integer constant 28 followed by the alias F3. The alias names the result column. It does not change the integer's value or request a floating-point conversion. Adding explicit spacing and AS reveals the interpretation.

SELECT 28F3;
SELECT 28 AS F3;

These statements have the same intended value and output name. Their equivalence follows from the parser's treatment of the numeric constant and following identifier. I rewrite the compact form before explaining the result because an explicit alias turns a puzzle into ordinary SELECT syntax. A readable statement should not require a guessing competition between the value and its label.

The naming rule is useful for ordinary expressions, but optional AS also permits mistakes to remain syntactically valid. A query can run successfully with an unexpected output column name. Correct parsing therefore does not establish that the statement expresses the author's intended calculation or output shape.

Read Float Literals in Scientific Notation

The E in 28E3 belongs to scientific notation. It scales the mantissa by ten raised to the given exponent, so the expression represents twenty-eight thousand. This is a floating-point constant rather than an integer constant that happens to wear a different alias. Use a separate explicit output name to keep both roles clear.

SELECT 28E3 AS ScientificNumber,
       28E0 AS UnscaledNumber,
       28E-3 AS SmallerNumber;

A positive exponent increases the magnitude, zero leaves it unchanged, and a negative exponent moves it toward zero. Those are mathematical meanings of the input notation, not performance measurements or observed workload values. The representation's data type still matters even when a particular numeric result looks like a whole number.

Do not interpret F as an alternative exponent marker in this syntax. Its role in the compact first statement is the alias identifier. Similar-looking notation in another language does not establish a numeric-literal rule in T-SQL. Read the grammar of the language that will actually compile the statement.

Inspect the Types of Float Literals

Use SQL_VARIANT_PROPERTY to inspect the base types of the constants without guessing from their displayed values. The integer constant and scientific-notation constant follow different typing rules. A results grid can format both neatly, which makes visual appearance an unreliable guide to the expression's numeric contract.

SELECT SQL_VARIANT_PROPERTY(28,'BaseType') AS IntegerConstantType,
       SQL_VARIANT_PROPERTY(28E3,'BaseType') AS ScientificConstantType,
       SQL_VARIANT_PROPERTY(28.0,'BaseType') AS DecimalConstantType;

Type inference affects later arithmetic, conversion, and comparison. An expression can introduce approximate numeric behavior into a larger calculation even if its isolated result looks exact. Keep the declared type deliberate when the calculation needs an exact decimal domain, and test the precision and scale of the complete expression.

I inspect expression metadata when a result's name or type surprises a reader. The inspection is particularly useful for generated SELECT lists, where missing punctuation and inferred types can be hard to see in a long statement. A type label gives the review a concrete fact to discuss.

Show Why F328 Is Different

An identifier beginning with letters can be parsed as a column reference. Without a matching column in scope, SELECT F328 fails name resolution. It does not split into an alias followed by a number and does not imply the earlier integer-constant interpretation. The direction of the text matters.

BEGIN TRY
    EXEC sys.sp_executesql N'SELECT F328;';
END TRY
BEGIN CATCH
    SELECT ERROR_NUMBER() AS ErrorNumber,
           ERROR_MESSAGE() AS ErrorMessage;
END CATCH;

The separate dynamic batch lets the surrounding TRY and CATCH report that compilation error from a lower execution level. Its text is fixed demonstration input. Do not use arbitrary user-supplied text to reproduce the example. Delimiting an unknown identifier would still leave it unknown; brackets change name parsing rather than inventing a numeric value.

One letter, two meanings: a diagram about the float literals

Recognize the Missing-Comma Trap

A missing comma can turn the next intended column into the previous expression's alias. That is more consequential than the number puzzle because the query can silently return fewer columns than its author expected. An application reading by column name can then receive a plausible name attached to the wrong value.

CREATE TABLE #AliasCustomer
(
    CustomerID int NOT NULL,
    CustomerName nvarchar(40) NOT NULL
);
INSERT #AliasCustomer VALUES (101,N'Sample Customer');
SELECT CustomerID CustomerName FROM #AliasCustomer;
SELECT CustomerID AS CustomerID,
       CustomerName AS CustomerName
FROM #AliasCustomer;

The first SELECT requests one expression with a misleading alias. The second requests both explicit expressions. Formatting one item per line helps expose missing separators, but formatting alone does not validate the returned shape. Check the expected column list in the application contract and in the query review.

Inspect Result Metadata Before Execution

The result-description function can reveal the output names and system types for a static statement. It is useful when the statement is not meant to be run during inspection. Review any reported error information too; a description attempt can fail because required objects or other compilation context are unavailable.

SELECT column_ordinal,name,system_type_name,
       error_number,error_message
FROM sys.dm_exec_describe_first_result_set(N'SELECT 28F3;',NULL,0);
SELECT column_ordinal,name,system_type_name,
       error_number,error_message
FROM sys.dm_exec_describe_first_result_set(N'SELECT 28E3 AS ScientificNumber;',NULL,0);

Use this as metadata evidence, not a replacement for validating a complex query's business logic. It cannot tell whether a syntactically valid alias matches the author's intended meaning. Which output name and type does the consumer expect? Compare that expectation directly with the described result.

Choose Float Literals or Exact Decimals Deliberately

Float literals are appropriate when an approximate numeric model is intended. For exact decimal calculations, choose a decimal type with accepted precision and scale, and use parameters or explicit conversion consistently. Do not introduce scientific notation merely to make a constant look shorter in an otherwise exact calculation.

DECLARE @ExactRate decimal(10,4) = 0.1250;
DECLARE @Amount decimal(12,2) = 80.00;
SELECT CAST(@Amount * @ExactRate AS decimal(12,2)) AS ExactResult;
SELECT CAST(28E3 AS decimal(12,2)) AS ExplicitlyConvertedValue;

A later conversion does not retroactively make every prior approximate calculation exact. Decide the arithmetic model before executing the expression, then verify rounding and range boundaries. Keep numeric typing and alias naming as two separate review questions even when they appear together in a short statement.

Write Explicit Aliases

Use AS whenever an expression needs an output alias. Keep commas visible and avoid deliberately compressed forms that resemble another numeric syntax. The small habit reduces the chance that a missing separator becomes a successful statement with an incorrect result contract.

Float literals explain one half of this example, and alias grammar explains the other half. Retain both explanations when teaching it so the reader can recognize the same parsing pattern in a real SELECT list. A query's ability to return a number is a modest achievement; returning the intended number under the intended name is the useful one.

Related reading on this blog: Why FLOAT Math Does Not Add Up in T-SQL Queries and Decimal Precision and Rounding in SQL Server.

Habits that keep a SELECT list honest: a checklist on the float literals

A successful parse is not proof of intent, it is the compiler's interpretation of the text it received.

Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.

SQL Datatype, SQL Scripts, SQL Server, Starting SQL
Previous Post
SQL SERVER – FIX: ERROR : Msg 3136, Level 16, State 1 – This differential backup cannot be restored because the database has not been restored to the correct earlier state
Next Post
SQL SERVER – FIX – Error: One or more files do not match the primary file of the database

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.