Scripts

Technical Article

View/Edit ASP Script from From SQL Server 7.0/2000

Ever want to display (and edit) ASP code from the original .asp file?  (like PHP's PHPInfo() function).To setup:  * Just create a .asp with SQL Server connectivity.  * Change @IISHostNameWWWPath to match your servername      -OR-     if SQL Server is on the same machine, use the next     line instead. (see […]

★ ★ ★ ★ ★ ★ ★ ★ ★ ★

You rated this post out of 5. Change rating

2002-04-22

631 reads

Technical Article

Change the User Defined Data type

User Defined Data Types (UDF) is one of the useful concepts in SQL Server. However UDF can't be modified after they are being used. You would have to remove your User Defined Data Type from each table before you can change it. This will be a big job under certain circumstances.This procedure changes all tables […]

★ ★ ★ ★ ★ ★ ★ ★ ★ ★

You rated this post out of 5. Change rating

2002-04-19

1,089 reads

Technical Article

Script to list all user and roles

This script list all the users defined for each database on the server, it give the database name, the login name and the role defined.Its use full to have quick view of witch users are dbo on witch databaseEnsure that you have the result in grid in query analyzer, and just cut and paste the […]

★ ★ ★ ★ ★ ★ ★ ★ ★ ★

(1)

You rated this post out of 5. Change rating

2002-04-18

982 reads

Technical Article

Write Reports from SQL to Disk (Even HTML!)

Ever need to write reports out to a folder? I have found that creating output files are SA-WEET! (and easy too) The sample script uses BCP to create an HTML file.This process works well for reports that need to be generated nightly and take too long to run in real time.  Use an SMTP mail […]

★ ★ ★ ★ ★ ★ ★ ★ ★ ★

You rated this post out of 5. Change rating

2002-04-18

4,556 reads

Technical Article

Decimal to Binary Conversion for event scheduling

This procedure was written to create an event schedule     where the schedule may have non-consecutive days.    The input for the procedure is START DATE, END DATE, and DAYMAP    The DAYMAP input parameter is a decimal number whose binary representation    describes the schedule days over potentially a 4 week period (read from right to left).    […]

★ ★ ★ ★ ★ ★ ★ ★ ★ ★

You rated this post out of 5. Change rating

2002-04-17

341 reads

Technical Article

Kill all Connections

There are times you want to kill all the connections in a database. This would do that trick. This can be very useful when you replace a database regularly and some connections still exist so your automated restore fails. You can issue this command to kill all the connections before issuing a restore command.

★ ★ ★ ★ ★ ★ ★ ★ ★ ★

You rated this post out of 5. Change rating

2002-04-17

2,550 reads

Blogs

November 2026 Car Update: MPG Comparisons

By

I’ve become an EV guy. I was talking with a friend who was selling...

T-SQL Snapshot Backups on Availability Group Secondary Replicas Continued

By

In a previous post I talked about how we can use T-SQL Snapshot Backups...

Memories of PASS Data Community Summit 2026

By

A bit of a photo dump, but a few fun memories for me from...

Read the latest Blogs

Forums

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...

Missing Returns

By Steve Jones - SSC Editor

Comments posted to this topic are about the item Missing Returns

Nobody Forgot Math With Calculators

By Steve Jones - SSC Editor

Comments posted to this topic are about the item Nobody Forgot Math With Calculators

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