X++ Enum Values in SQL: How Stored Numbers Work in D365

How-to basics · Updated November 22, 2026

In X++, an enum field is stored in the database as an integer, not as the enum’s displayed label. The integer corresponds to a value in the enum’s application metadata; SQL can show the stored number, but you need that metadata to translate it reliably into a name or user-facing label.

The short answer: enums become integers

An X++ enumeration gives code a readable set of named choices. For example, a field might use a status enum with choices such as Open, InProgress, and Closed. In an SQL table, the corresponding column is typically an integer column containing the numeric value for the selected choice. The words shown in the application are not generally stored in that column.

A familiar example is the standard NoYes enum: No is represented by 0 and Yes by 1. That simple mapping is useful for illustration, but do not assume that every enum follows the same numbering pattern. The authoritative mapping is the enum definition in the application version running against the data.

So if a query returns 1, that tells you the stored enum number. It does not, on its own, tell you what the user saw. To interpret it, identify the field’s enum type and check the corresponding enum element in metadata.

How X++ enum mapping works

An enum is a type defined in the application, with named elements and associated numeric values. A table field is declared using that enum type. When a record is saved, the database stores the integer representation for the field. X++ code can refer to the named element, which is safer and easier to understand than embedding a raw number.

For example, an X++ comparison should use the enum’s symbolic value rather than a guessed integer. Conceptually, code checks whether a status field equals the enum element for Closed. The compiler and application metadata connect that element to its underlying number when data is read or written.

  • Enum type: defines the available choices.
  • Enum element: names one choice, such as Yes or No.
  • Stored value: the integer persisted for the selected element.
  • Label: localized text that may be displayed in the user interface.

These are related but distinct things. A label can change or be translated without changing the basic purpose of the enum element. Likewise, seeing an integer in SQL is not evidence that the application is displaying that integer to users.

Finding the value in SQL

For a permitted read-only investigation, a query can show which integer values appear in a column and how many records use each one. The following is an illustrative query for a field named SalesStatus on a table named SalesTable; verify the actual table and field in your application metadata before using it.

SELECT SalesStatus, COUNT(*) AS RecordCount
FROM dbo.SalesTable
GROUP BY SalesStatus
ORDER BY SalesStatus;

The result might contain rows such as 0, 1, and 2 with counts beside them. Those numbers are useful for checking data distribution, spotting an unexpected value, or comparing records. They are not a dependable substitute for looking up the enum definition. A number may mean something different for another enum, even if the field name sounds similar.

To read individual records, select the enum column alongside a key or other identifying field. If the application is partitioned or company-specific, consider the relevant company or partition context when interpreting the results. The exact columns and SQL access available depend on the product version and environment.

How to look up enum names and labels

Start by identifying the table field’s enum type in the application’s metadata or development tools. Then inspect that enum’s elements and their assigned values. In a Dynamics 365 Finance and Operations development environment, this is typically done through the application model and its metadata in Visual Studio. The SQL column name alone may not reveal the enum type, so trace the field definition rather than guessing from the column’s contents.

X++ provides conversion functions that can help when inspecting values in application code. For example, enum2int converts an enum value to its integer representation, while enum2str converts an enum value to a string representation. Use the appropriate function in the context of a known enum type; neither function makes an arbitrary SQL number self-describing. If you need the localized text shown in a particular interface, check the label metadata and language context instead of assuming a string conversion is the same as a user-facing label.

A practical lookup workflow is:

  1. Find the table field definition and note its enum type.
  2. Open that enum’s metadata and identify the element values.
  3. Match the integer from SQL to the element with that value.
  4. If the question concerns displayed wording, check the label for the user’s language.
  5. Repeat the check against the same application build that produced the data.

Labels, symbols, and stored numbers are different

Confusion often starts when a screen displays a phrase such as “In progress,” while SQL shows 2. The displayed phrase may be a translated label, the source code may refer to a symbolic enum element, and the database stores the element’s integer. Treating those three representations as interchangeable causes problems in reports and integrations.

Labels are meant for people and may vary by language. Enum element names are useful in code and metadata, but they are not necessarily the text shown in every locale. Numeric values are compact and stored with the record, but they have meaning only when paired with the correct enum definition. A report that exports raw numbers should therefore include a documented mapping or perform a supported conversion before presenting them to business users.

Extensible enums and version changes

Dynamics 365 Finance and Operations supports extensibility, including extensions to eligible enums. That means the full set of choices may come from the base application and installed extensions, rather than from one source file. The metadata in a particular deployed environment is the relevant reference; a list copied from another environment or an old document may not include the same elements.

Do not infer an enum number solely from the element’s visible position in a list, and do not assume that values are contiguous. Extensions and application changes make that shortcut particularly unreliable. When investigating data across environments or releases, confirm the enum metadata for each environment and check that the application versions and extensions are aligned.

For the same reason, avoid changing an enum’s numeric mapping or reusing a value casually in custom development. Existing records already contain numbers. If a number is reassigned to a different meaning, old data can appear to represent the new choice even though it was originally saved for another one. Follow the platform’s extension and upgrade guidance, and preserve the meaning of values that are already in use.

Common problems and safer practices

A frequent mistake is writing SQL that filters on a guessed number, such as assuming that 1 always means Yes or Closed. The number 1 has no universal enum meaning. Another is editing the database directly to change a status. Even if the integer looks correct, a direct update can bypass application validation, business logic, related updates, and audit behavior.

  • Use named enum elements in X++ instead of magic numbers.
  • For SQL analysis, verify the field’s enum type before interpreting a value.
  • Do not update application tables directly unless a supported procedure explicitly permits it.
  • Recheck mappings after deploying an application update or extension.
  • Keep labels and numeric mappings separate in reports and external interfaces.

Direct SQL access is also environment-dependent. In many cloud-hosted Dynamics 365 Finance and Operations production environments, customers do not have general direct access to the application database. Use supported options such as data entities, OData where appropriate, or an approved export or reporting mechanism. Older or on-premises deployments may allow database reads under specific operational rules, but database access does not make direct writes a safe application integration method. Follow the rules for the exact deployment.

When to use X++ versus SQL

Use X++ when application behavior, validation, or a business process is involved. X++ can work with enum types directly, making the intent clearer and reducing the chance of confusing values across fields. Use SQL, where access is approved, for read-only analysis such as counting values or investigating a data issue. SQL is good at showing what is stored; it does not automatically supply the application’s enum labels.

For integrations and reporting, prefer a supported data surface that exposes the fields and representations intended for that use. Check how the chosen entity or export represents enum fields instead of assuming it will return either labels or integers in every case. If consumers need readable text, define how that text is produced and account for language and application-version changes.

Frequently Asked Questions

Are X++ enum values stored as strings in SQL?
No. A table enum field is typically stored as an integer. The application metadata maps that number to an enum element, and labels may be used for display.

How can I find what an enum number means?
Identify the table field’s enum type, then inspect that enum’s element values in the metadata for the same application build. Do not look up a number without first confirming the enum type.

Does enum value 1 always mean Yes?
No. It means Yes for the standard NoYes mapping, but enum numbers are specific to their enum definitions. The same integer can mean something else for another field.

Can I change an enum value with an SQL update?
A direct update is generally unsafe and may be unsupported, especially in cloud environments. Use the application’s supported business logic or data-management mechanisms, and follow deployment-specific guidance.

Are enum labels stored in the table?
Usually not in the enum field itself. The field stores the integer; labels come from application metadata and can be localized. A separate text field or export may have different behavior, so check its definition.

Do enum numbers stay the same in every environment?
They should be interpreted using the metadata deployed with the data. Differences in versions or extensions can make assumptions based on another environment’s enum list unreliable.

Related

Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.

More in How-to basics

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.