Scripts

Technical Article

CSV Lists of Columns in Different Formats

This script creates comma separated lists of columns in different formats. These lists can be copied and pasted into other T-SQL statements.  The lists are formatted as: a simple list of column names, a list with the column names as declared variables (@ + column name + data type), a list with column names as […]

★ ★ ★ ★ ★ ★ ★ ★ ★ ★

You rated this post out of 5. Change rating

2002-12-26

246 reads

Technical Article

Dynamic DBCC DBREINDEX

This script uses sysobjects and sysindexes to ID all tables in a database that are indexed, and/or clustered.  It then runs through per table all of the indexes and runs DBREINDEX with their fillfactor.  This eliminates having to maintain a list of all indexes and having code fail when it tries to modify indexes that […]

★ ★ ★ ★ ★ ★ ★ ★ ★ ★

You rated this post out of 5. Change rating

2002-12-19

1,837 reads

Technical Article

Net Send

Yee Haa, as if we couldn't annoy our users more with message boxes, emails, and other friendly pop ups ;P here comes the net send. Has a test for success to determine if the send worked. If an invalid name is entered it can take a bit to fail, so don't use this from a […]

★ ★ ★ ★ ★ ★ ★ ★ ★ ★

You rated this post out of 5. Change rating

2002-12-18

382 reads

Technical Article

Script to gather informations on databases

The script is design to gather informations on the growth of the databases per server (except the system ones).It is collecting in the 'databases' table of the master database for current information and in 'histodatabases' for old ones.It is possible to schedule the stored procedure.The column Serveur is only for gathering information on one server […]

★ ★ ★ ★ ★ ★ ★ ★ ★ ★

(1)

You rated this post out of 5. Change rating

2002-12-17

358 reads

Technical Article

Automatically Restoring from Production

Came across a great script from Ken Kaufman on copying backups using xp_cmdshell.  Thought I'd contribute a script I wrote that builds on that to restore the latest production backup to a testing or development server.  In this case I routinely create all my production backups to a network share and then use that source […]

★ ★ ★ ★ ★ ★ ★ ★ ★ ★

You rated this post out of 5. Change rating

2002-12-16

691 reads

Blogs

Embracing Hardship with Gratitude

By

I once kept a gratitude journal and I still have a task on my...

Integrating AgentDBA into Claude Code with MCP

By

The goal is simple: register AgentDBA as an MCP server in Claude Code, so...

Finally! I Can Read Numbers in SSMS

By

I was excited to try out the latest release of SSMS, v22.12.1 for this...

Read the latest Blogs

Forums

Transport-level error when querying Excel metadata using sys.sp_tables_ex...

By jellybean

Hi everyone, We previously used the Microsoft Access Database Engine 2016 (ACE) provider. As...

Perform Regression After Migration from SQL 2014 TO 2022 (Physical to Virtual)

By abdalah.mehdoini

Hello, We recently migrated a database from SQL Server 2014 to SQL Server 2022....

Detecting Outliers in Power BI using Z-Score

By Dinesh Asanka

Comments posted to this topic are about the item Detecting Outliers in Power BI...

Visit the forum

Question of the Day

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
)
GO
There 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