Scripts

Technical Article

Get the Table Structure using a simple query

This query will solve problems related to Table structure. Using this query you can have the complete table structure for all the user tables with Table Name, Column Name, Data Type, and Null attributes of a column.You can run this script in Query Analyzer or make use of it in your front-end to give table […]

★ ★ ★ ★ ★ ★ ★ ★ ★ ★

(2)

You rated this post out of 5. Change rating

2003-04-02

5,206 reads

Technical Article

Restore last backup to a different server/database

Finds the last available backup for a specified database (local or remote server), then restores the backup onto an existing database on the local server.The script will kill all non-system processes in the destination database to allow the script to be scheduled at night regardless is anyone is still connected.The logical and physical names are […]

★ ★ ★ ★ ★ ★ ★ ★ ★ ★

You rated this post out of 5. Change rating

2003-03-31

797 reads

Technical Article

Date without Time (corrected)

Some time you need to know only Date without Time.This is simple function that allows you truncate datetime field to date only.This function can help you to construct dynamic T-SQL for select date period. P.S. Thanks for ispaleny! Conversion only for real not enough! It is necessary convert to real that correct errors near the […]

★ ★ ★ ★ ★ ★ ★ ★ ★ ★

(1)

You rated this post out of 5. Change rating

2003-03-28

443 reads

Technical Article

Enhanced sp_password

This is a sp_password enhanced by Dmitri Bobkov (see http://www.sqlservercentral.com/scripts/contributions/718.asp) and re-enhanced with a small changes from SQL2kSP3.For SQL Server in Mixed Authentication mode this stored procedure helps to validate users password. Currently this procedure checks for the next requrements: password must have length at least 8 characters plus among them at least one digit […]

★ ★ ★ ★ ★ ★ ★ ★ ★ ★

You rated this post out of 5. Change rating

2003-03-27

500 reads

Technical Article

T-SQL to Export Table Structure to a script

When you want to export a table structure to T-SQL, everyone always points you to Enterprise Manager, or a script that calls BCP.Sometimes, a developer either doesn't have access to those tools, or just doesn't want to use them (like me) out of spite.I made this T-SQL because it was educational, and noone else seems […]

★ ★ ★ ★ ★ ★ ★ ★ ★ ★

(2)

You rated this post out of 5. Change rating

2003-03-26

4,093 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

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

Missing Returns

By Steve Jones - SSC Editor

Comments posted to this topic are about the item Missing Returns

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