Module 03 · Lesson 5 of 13Detailed study · about 15 min

Clean, calculate and convert values

Built-in functions transform text, numbers and dates. Conversion functions interpret values as a chosen type.

Understand the idea

A conversion is an interpretation, not just a display change. The text 12.50 can become a decimal, while twelve cannot be parsed by ordinary numeric conversion. TRY functions help identify bad inputs, but silently dropping their NULL results can hide data quality problems.

Key ideas in simple English
ConceptWhat it means
TRIM / UPPER / SUBSTRClean and reshape text.
ROUND / ABSWork with numeric values.
DATEADD / DATEDIFFCalculate date changes and differences.
TRY_TO_NUMBERReturn NULL instead of a conversion error for invalid numeric text.
IFFChoose between two expressions using a condition.

A concrete example

Results: EAST, 101, 12.35, 7, 2026-02-01, 3, 12.50, NULL and yes. SQL NULL may be displayed differently by your client.

Remember: Treat it as a conversion outcome to inspect; decide on a reject or correction rule instead of assuming the original number was zero.

Explain it step by step · full theory

Understand the idea

A conversion is an interpretation, not just a display change. The text 12.50 can become a decimal, while twelve cannot be parsed by ordinary numeric conversion. TRY functions help identify bad inputs, but silently dropping their NULL results can hide data quality problems.

Date calculations need a unit. Adding one day differs from adding one month. Keep formats explicit when reading date strings and explain whether a failed conversion should be rejected, corrected or allowed as NULL.

Words used in this lesson
TRIM / UPPER / SUBSTR
Clean and reshape text.
ROUND / ABS
Work with numeric values.
DATEADD / DATEDIFF
Calculate date changes and differences.
TRY_TO_NUMBER
Return NULL instead of a conversion error for invalid numeric text.
IFF
Choose between two expressions using a condition.

See how it works

Choose a step to explore the idea at your own pace.

Open the interactive explanation
Interactive explainer1 / 3

Clean, calculate and convert values

Sample rows
Question

Choose the input

Built-in functions transform text, numbers and dates. Conversion functions interpret values as a chosen type.

Automatic playback is off for reduced motion. Select any step or use Previous and Next. Illustrations explain behavior; they are not live measurements.

Read the complete diagram explanation
  1. Choose the input

    Built-in functions transform text, numbers and dates. Conversion functions interpret values as a chosen type.

  2. Apply the SQL

    A conversion is an interpretation, not just a display change. The text 12.50 can become a decimal, while twelve cannot be parsed by ordinary numeric conversion. TRY functions help identify bad inputs, but silently dropping their NULL results can hide data quality problems.

  3. Explain the result

    Treat it as a conversion outcome to inspect; decide on a reject or correction rule instead of assuming the original number was zero.

Try the SQL or command

Read → predict → run in your learning environment → compare. You can also learn by reading without an account.

New to SQL? Where to run it and how to read it

A query is a question written in SQL. Snowflake runs it and returns a result table. This website shows examples; it does not connect to your account.

  1. No account yet? Read and predict the output first. Follow the account and Snowsight lesson when you are ready.
  2. For SQL practice, use a learning account in Snowsight and select an authorized role and warehouse. A role determines permissions; a warehouse supplies processing power. Follow the example’s database/schema setup when it refers to stored objects.
  3. Read the entire example, including comments beginning with --. Run the selected statement or labeled block in the stated order. Examples labeled Python, shell or HTTP belong in that client, not in a SQL editor.
  4. Compare values and row counts with the explained result. If an example deliberately causes an error, follow its rollback and cleanup steps before continuing.
SELECT / FROM
Choose the values to return / identify their input.
VALUES / COLUMN1
VALUES supplies tiny example rows. COLUMN1 means their first column, COLUMN2 their second.
AS / WITH
AS gives a result a readable name. WITH names a temporary query step within one statement.
NULL / ::
NULL means missing or unknown. The :: notation converts a value to a named data type.
Session
One connection and its settings. Keep related transaction steps in the same session.
Database.schema.table
A full address for stored data. It is separate from the warehouse that processes queries.

Need the L2_OBJECTS_LAB setup? Open the first database-object lesson →

Help with common practice errors
  • No active warehouse: select a warehouse your role can use. Do not assume you need to create a new one.
  • Object missing or not authorized: check the full name, required setup and active role. Ask the account owner for access if needed.
  • Object already exists: setup may already have run. Read the current state or choose a fresh lab name consistently; do not add OR REPLACE blindly.
  • Different result: check whether an earlier INSERT or UPDATE changed the data. VALUES examples provide their own fresh input for each statement.

Before running this lesson

Use an authorized learning account and warehouse. VALUES examples need no stored tables. Object-changing examples use separate disposable tables in L2_OBJECTS_LAB.SALES from the first lesson; run each setup once with a fresh name.

Small transformations with visible outcomes

SQL · example
SELECT UPPER(TRIM('  east  ')) AS REGION, SUBSTR('ORDER-101',7,3) AS ID_TEXT,
 ROUND(12.346,2) AS ROUNDED, ABS(-7) AS DISTANCE,
 DATEADD(day,1,DATE '2026-01-31')::DATE AS NEXT_DAY,
 DATEDIFF(day,DATE '2026-01-01',DATE '2026-01-04') AS DAYS,
 TRY_TO_DECIMAL('12.50',10,2) AS VALID_AMOUNT,
 TRY_TO_NUMBER('bad') AS INVALID_AMOUNT, IFF(2 > 1,'yes','no') AS ANSWER;

What to expect and why

Results: EAST, 101, 12.35, 7, 2026-02-01, 3, 12.50, NULL and yes. SQL NULL may be displayed differently by your client.

Check your understanding

Choose an answer, then check your reasoning. This is practice, not a scored test.

What should you do with a NULL returned by TRY_TO_NUMBER for bad input?

Try it yourself

What should you do with a NULL returned by TRY_TO_NUMBER for bad input?

Compare your reasoning

Treat it as a conversion outcome to inspect; decide on a reject or correction rule instead of assuming the original number was zero.

Official sources and curriculum

Module 03 · See module scope