有谁熟悉这个错误?非常感谢:)
我的代码:
declare @FromDate date
declare @ToDate date
set @FromDate = '2017/01/01'
set @ToDate = '2017/02/28'
/*********************** INVOICE DETAILS **************************************/
--declare @FromDate date
--declare @ToDate date
--set @FromDate = '1/1/2017'
--set @ToDate = '2/28/2017'
if object_id('tempdb..#tmpInvoiceDetails') IS NOT NULL
begin
drop table #tmpInvoiceDetails
end
create table dbo.#tmpInvoiceDetails
(
[PurchaseOrderKey] uniqueidentifier,
[AgreementKey] varchar(40),
[CreatedDate] datetime,
[SalesOrderID] varchar(30),
[ConfirmedInvoiceNumber] varchar(50),
[CurrencyCode] varchar(5),
[ExtendedLineItemAmount] int,
[ExtendedLineItemAmountUSD] int
)
insert into dbo.#tmpInvoiceDetails
(
[PurchaseOrderKey],
[AgreementKey],
[CreatedDate],
[SalesOrderID],
[ConfirmedInvoiceNumber],
[CurrencyCode],
[ExtendedLineItemAmount],
[ExtendedLineItemAmountUSD]
)
select
[CreatedDate],
[SalesOrderID],
[PurchaseOrderKey],
[AgreementKey],
[ConfirmedInvoiceNumber],
[CurrencyCode],
[ExtendedLineItemAmount],
[ExtendedLineItemAmountUSD]
from [dbo].[SalesOrderLineItem]
where [CreatedDate] >= @FromDate
and [CreatedDAte] < @ToDate
--create index on temp audit table
create nonclustered index [tmpIDX] on [dbo].[#tmpInvoiceDetails]
(
[CreatedDate] ASC,
[PurchaseOrderKey] ASC
)
我收到此错误:
Msg 206,Level 16,State 2,Line 31
操作数类型冲突:smalldatetime与uniqueidentifier不兼容。
我已经尝试更改日期格式但仍然相同。
答案 0 :(得分:1)
您的列顺序错误:
insert into dbo.#tmpInvoiceDetails
(
[PurchaseOrderKey],
[AgreementKey],
[CreatedDate],
...
select
[CreatedDate],
[SalesOrderID],
[PurchaseOrderKey],
...
因此,您将CreatedDate插入PurchaseOrderKey,将SalesOrderID插入AgreementKey等。