How SQL Server stores data types: DATETIMEOFFSET
If you’d like to check out the previous instalment in this series on storing dates and times, click here. I avoided mentioning this data type because I didn’t think...
2021-06-16
51 reads
If you’d like to check out the previous instalment in this series on storing dates and times, click here. I avoided mentioning this data type because I didn’t think...
2021-06-16
51 reads
Whenever I restore a database — especially one I obtained outside of my regular environment (for example a customer database, a development database, or even a sample database like...
2021-06-09
58 reads
Last week I wrote about recovering data after an unplanned outage, and this week I’m contemplating a thing that would be considered bad in those circumstances as well as...
2021-06-02
28 reads
One of my special interests as an autistic person is understanding mechanical components of a computer, both analog and digital. In the olden days, we had devices known as...
2021-05-26
44 reads
A few years ago, I wrote that a CPU is “a hot mess of on-off switches.” There’s more to it than that when you get into the weeds of...
2021-05-31 (first published: 2021-05-19)
447 reads
In February 2011, Pat Wright invited us to talk about Automation: So the topic I have chosen for this month is Automation! It can be Automation with T-SQL or...
2021-05-12
28 reads
At the end of 2010, Sean McCown (blog | Twitter) invited us to talk about resolutions: Things like getting certified, or perfecting a process, or taking management classes, etc...
2021-05-05
26 reads
There comes a time when we heed a certain call. The call is to avoid dangerous undocumented DBCC commands in SQL Server, especially those that bypass built-in protections. I’m...
2021-04-28
34 reads
Next week on Wednesday is the Calgary Data User Group’s second event for 2021, and the second event as a member of Microsoft’s new Azure Data Community. Since last...
2021-04-21
29 reads
Click here to read previous retrospective entries. From Steve Jones (blog | Twitter) in December 2010 comes the question “What issues have you had in interacting with the business to get your...
2021-04-15 (first published: 2021-04-14)
195 reads
By Steve Jones
I’ve become an EV guy. I was talking with a friend who was selling...
In a previous post I talked about how we can use T-SQL Snapshot Backups...
By Steve Jones
A bit of a photo dump, but a few fun memories for me from...
Hello, We recently migrated a database from SQL Server 2014 to SQL Server 2022....
Comments posted to this topic are about the item Detecting Outliers in Power BI...
Comments posted to this topic are about the item Missing Returns
I have a few tables in my SQL 2025 database:
CREATE TABLE [dbo].[Customer] ( [CustomerID] [int] NOT NULL, [CustomerName] [varchar] (200) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, [AddressKey] [int] NULL, [CustomerStatus] [int] NULL, [CustomerContact] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [ContactEmail] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [PreferredName] [char] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ) ON [PRIMARY] GO ALTER TABLE [dbo].[Customer] ADD CONSTRAINT [CustomerPK] PRIMARY KEY CLUSTERED ([CustomerID]) ON [PRIMARY] GO CREATE TABLE [dbo].[Orders] ( [OrderID] [int] NOT NULL, [CustomerID] [int] NOT NULL, [ProductID] [int] NOT NULL, [OrderDate] [date] NOT NULL, [Quantity] [int] NOT NULL ) ON [PRIMARY] GO ALTER TABLE [dbo].[Orders] ADD CONSTRAINT [PK__Orders__C3905BAFE0146D59] PRIMARY KEY CLUSTERED ([OrderID]) ON [PRIMARY] GO ALTER TABLE [dbo].[Orders] ADD CONSTRAINT [FK_Orders_Customers] FOREIGN KEY ([CustomerID]) REFERENCES [dbo].[Customers] ([CustomerID]) GO ALTER TABLE [dbo].[Orders] ADD CONSTRAINT [FK_Orders_Products] FOREIGN KEY ([ProductID]) REFERENCES [dbo].[Products] ([ProductID]) GO CREATE TABLE dbo.CustomerReturn ( EntryID INT NOT NULL CONSTRAINT CustomerReturnPK PRIMARY KEY , CustomerID INT , ReturnDate DATETIME , OrderID INT NOT NULL ) GOThere are multiple rows in all these tables. I am trying to find how many customers have never returned anything, and I run this:
SELECT count(*)
FROM dbo.Customer
WHERE CustomerID NOT IN
(
SELECT CustomerID FROM dbo.CustomerReturn
);
I get zero rows, but I know there are customers who have not returned anything. What is wrong? See possible answers