Tags

, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,


A SQL Puzzle | What is the SUM and Count of an Empty Table?

Let’s start by creating some sample data.

--

CREATE TABLE testEmpty
(
	ID INT
)
GO

SELECT SUM(ID) Sums FROM testEmpty
SELECT COUNT(*) Cnts FROM testEmpty

CREATE TABLE testEmpty1
(
	ID INT NOT NULL
)
GO

SELECT COUNT(*) Cnts FROM testEmpty1
SELECT SUM(ID) Sums FROM testEmpty1

--

If you run the above statements for both the tables, What will be the sum value and the Count value for the above queries and their reasons ?

Please add answers in the comments section !

Cheers, Keep Learning !!

Pawan Kumar Khowal

MSBISKills.com