When I try this:
SELECT *
-- INTO DB2.dbo.CustomerOrderLines
FROM DB1.dbo.CustomerOrderLines
INNER JOIN DB1.dbo.CustomerOrders ON DB1.dbo.CustomerOrders.Order_Display_Ref = DB1.dbo.CustomerOrderLines.Order_Display_Ref
WHERE DB1.dbo.CustomerOrders.Delivered_Date BETWEEN '2009-09-23' and '2009-09-24'
it show the rows correctly.
When I try to copy the contents from one table in DB1 into the same table in DB2 (and create it if it does not exist):
SELECT *
INTO DB2.dbo.CustomerOrderLines
FROM DB1.dbo.CustomerOrderLines
INNER JOIN DB1.dbo.CustomerOrders ON DB1.dbo.CustomerOrders.Order_Display_Ref = DB1.dbo.CustomerOrderLines.Order_Display_Ref
WHERE DB1.dbo.CustomerOrders.Delivered_Date BETWEEN '2009-09-23' and '2009-09-24'
it fails with
Msg 2705, Level 16, State 3, Line 1 Column names in each table must be unique. Column name 'Order_Display_Ref' in table 'CustomerOrderLines' is specified more than once.
SELECT * INTO and INSERT INTO SELECT * work fine when copying other tables from one database into another, but they do not use JOINS.
What is my mistake?