Advent of 2025, Day 4 – SQL Server 2025 – New T-SQL functions – Product()

In this Microsoft SQL Server 2025 series:

  1. Dec 01: Microsoft SQL Server 2025 – Introduction and installation
  2. Dec 02: Microsoft SQL Server 2025 – New T-SQL functions – native JSON data type and some functions
  3. Dec 03: Microsoft SQL Server 2025 – New T-SQL functions – JSON Index

SQL Server 2025 introduces a new T-SQL function, called PRODUCT(). The function returns the product of all the numeric (and only) values in the expression. NULL values are ignored and DISTINC values can be set.

PRODUCT with NULL

Product() function returns result that NULL values are ignored and product is calculated based on all integers present.

-- NULL
SELECT 
 PRODUCT(vals)  
FROM (VALUES (4), (4), (3), (2), (NULL) ) AS MyTable(vals);
-- result: 4*4*3*2 = 96; NULL IS IGNORED

PRODUCT using DISTINCT

Using DISTINCT will remove duplicates and calculate product only with unique values. Also NULL values are ignored.

-- DISTINCT
SELECT 
 PRODUCT(DISTINCT vals)  
FROM (VALUES (4), (4), (3), (2), (NULL) ) AS MyTable(vals);
-- result: 4*3*2 = 24; NULL IS IGNORED

PRODUCT using OVER Clause

PRODUCT() function also supports the OVER clause to determine the partitioning and ordering of a rowset before the function is applied.

-- OVER CLAUSE with return rate example
SELECT DISTINCT ProductGroup
   ,PRODUCT(1 + RR_Value) OVER (PARTITION BY ProductGroup ORDER BY ProductGroup) AS CalculatedReturn
FROM (VALUES (0.1626, 'Group1'),
             (0.0483, 'Group2'),
             (0.2689, 'Group3'),
             (0.1944, 'Group1'),
             (0.2423, 'Group1'),
             (0.3423, 'Group3')
) AS MyTable2(RR_Value, ProductGroup);

A useful T-SQL Function that solves multiple issues regarding multiplications and behaves the same way as SUM(), COUNT() or similar aggregation functions in T-SQL.

Tomorrow we will look into the new T-SQL functions BASE64(); BASE64_ENCODE() and BASE64_DECODE().

As always, the code is available at my Github: https://github.com/tomaztk/SQLServer2025

Happy coding!

Tagged with: , , ,
Posted in SQL Server
19 comments on “Advent of 2025, Day 4 – SQL Server 2025 – New T-SQL functions – Product()
  1. […] Dec 04: Microsoft SQL Server 2025 – New T-SQL functions – Product() […]

    Like

  2. […] Dec 04: Microsoft SQL Server 2025 – New T-SQL functions – Product() […]

    Like

  3. […] Dec 04: Microsoft SQL Server 2025 – New T-SQL functions – Product() […]

    Like

  4. […] Dec 04: Microsoft SQL Server 2025 – New T-SQL functions – Product() […]

    Like

  5. […] Dec 04: Microsoft SQL Server 2025 – New T-SQL functions – Product() […]

    Like

  6. […] Dec 04: Microsoft SQL Server 2025 – New T-SQL functions – Product() […]

    Like

  7. […] Dec 04: Microsoft SQL Server 2025 – New T-SQL functions – Product() […]

    Like

  8. […] Dec 04: Microsoft SQL Server 2025 – New T-SQL functions – Product() […]

    Like

  9. […] Dec 04: Microsoft SQL Server 2025 – New T-SQL functions – Product() […]

    Like

  10. […] Dec 04: Microsoft SQL Server 2025 – New T-SQL functions – Product() […]

    Like

  11. […] Dec 04: Microsoft SQL Server 2025 – New T-SQL functions – Product() […]

    Like

  12. […] Dec 04: Microsoft SQL Server 2025 – New T-SQL functions – Product() […]

    Like

  13. […] Dec 04: Microsoft SQL Server 2025 – New T-SQL functions – Product() […]

    Like

Leave a comment

Follow TomazTsql on WordPress.com
Programs I Use: SQL Search
Programs I Use: R Studio
Programs I Use: Plan Explorer
Rdeči Noski – Charity

Rdeči noski

100% of donations made here go to charity, no deductions, no fees. For CLOWNDOCTORS - encouraging more joy and happiness to children staying in hospitals (http://www.rednoses.eu/red-noses-organisations/slovenia/)

€2.00

Top SQL Server Bloggers 2018
TomazTsql

Tomaz doing BI and DEV with SQL Server and R, Python, Power BI, Azure and beyond

Discover WordPress

A daily selection of the best content published on WordPress, collected for you by humans who love to read.

Revolutions

Tomaz doing BI and DEV with SQL Server and R, Python, Power BI, Azure and beyond

Reeves Smith's SQL & BI Blog

A blog about SQL Server and the Microsoft Business Intelligence stack with some random Non-Microsoft tools thrown in for good measure.

SQL Server

for Application Developers

Business Analytics 3.0

Data Driven Business Models

SQL Database Engine Blog

Tomaz doing BI and DEV with SQL Server and R, Python, Power BI, Azure and beyond

Search Msdn

Tomaz doing BI and DEV with SQL Server and R, Python, Power BI, Azure and beyond

R-bloggers

Tomaz doing BI and DEV with SQL Server and R, Python, Power BI, Azure and beyond

Data Until I Die!

Data for Life :)

Paul Turley's SQL Server BI Blog

sharing my experiences with the Microsoft data platform, Fabric, enterprise Power BI, SQL Server BI, Data Modeling, SSAS Design, SSRS, Dashboards & Visualization since 2009

Grant Fritchey

Intimidating Databases and Code

Madhivanan's SQL blog

A modern business theme

Alessandro Alpi's Blog

DevOps could be the disease you die with, but don’t die of.

Paul te Braak

Business Intelligence Blog

Sql Insane Asylum (A Blog by Pat Wright)

Information about SQL (PostgreSQL & SQL Server) from the Asylum.

Gareth's Blog

A blog about Life, SQL & Everything ...

SQLPam's Blog

Life changes fast and this is where I occasionally take time to ponder what I have learned and experienced. A lot of focus will be on SQL and the SQL community – but life varies.

William Durkin

William Durkin a blog on SQL Server, Replication, Performance Tuning and whatever else.

$hell Your Experience !!!

As aventuras de um DBA usando o Poder do $hell

Design a site like this with WordPress.com
Get started