这不是从 sql server 中的select 语句到create 表的正确方法
使用INTO 子句
SELECT...INTO 在默认文件组中创建一个新表并插入
从查询到它的结果行
SELECT A.Col1,A.col2,B.Col1 as B_col1,B.col3...
INTO new_temp
FROM [Sales].[dbo].[SecondarySales] A
LEFT JOIN [Sales].[dbo].[PrimarySales] B
ON [Sales].[dbo].[SecondarySales].[SalesFromID] = [Sales].[dbo].[PrimarySales].[SalesToID];
正如HART CO 在注释中提到的,如果两个表中的任何列名相同,则表中的列名应该是唯一的,那么您必须提供别名。
更新:
SELECT a.PrimarySalesId,a.SalesFromID,a.SalesToID,a.InvoiceNumber,a.InvoiceDate,
a.ReceiveDate,a.TotalQuantity,a.TotalAmount,a.IsAcknowledgementRequired,
a.IsReceived,a.SalesType,a.AcknowlegeDate,a.Status,a.SalesMan,
a.RecordCreationDate,a.ModifiedOn,a.CreatedBy,a.ModifiedBy,
b.SecondarySalesID,b.AcknowlegeDate,
b.CreatedBy,
b.InvoiceDate as SecondarySales_InvoiceDate,
b.InvoiceNumber as SecondarySales_InvoiceNumber,
b.IsAcknowledgementRequired,
b.IsReceived as SecondarySales_IsReceived,
b.Modified,
b.ModifiedOn as SecondarySales_ModifiedOn,
b.ReceiveDate,
b.RecordCreationDate,
b.SalesFromID as SecondarySales_SalesFromID,
b.SalesMan as SecondarySales_SalesMan,
b.SalesManID,
b.SalesToID as SecondarySales_SalesToID,
b.SalesType,
b.Status,
b.TotalAmount,
b.TotalQuantity
INTO new_temp
FROM [Sales].[dbo].[SecondarySales] b
LEFT JOIN [Sales].[dbo].[PrimarySales] a
ON b.SalesFromID = a.SalesToID