我想在我的AfterParse_CA_Events中添加一个ErrorMessage列。所以我可以看到我的桌子缺少哪些数据。
CREATE TABLE [dbo].[AfterParse_CA_Events](
[EventID] [varchar](32) NOT NULL,
[MessageID] [bigint] NOT NULL,
[cdtprFunction] [varchar](32) NULL,
[CreationDate] [datetime] NULL,
[MsgDefIdr] [varchar](32) NULL,
[CFI] [varchar](50) NULL,
[MndtryVlntryEvtTp] [varchar](32) NULL,
[EventProcessingType] [varchar](4) NULL,
[EventType] [varchar](4) NULL,
[RecordDate] [date] NULL,
[EffectiveDate] [date] NULL,
[DueBillRdmDate] [date] NULL,
[OldQuantity] [varchar](32) NULL,
[PaymentDate] [date] NULL,
[LastChangeBy] [varchar](50) NULL,
[LastChangeDate] [datetime] NULL,
[EventDescription] [varchar](max) NULL,
[CUSIP] [varchar](32) NULL,
[MQ_DateTime] [datetime2](7) NULL,
[Symbol2] [varchar](32) NULL,
[AssetClass] [varchar](5) NULL,
[AssetType] [varchar](5) NULL,
[DividendType] [varchar](5) NULL,
[ExDividendDate] [date] NULL,
[LSCI_DateOfRecord] [date] NULL,
[RoundingDesc] [varchar](4) NULL,
[CompleteStatus] [varchar](4) NULL,
[ErrorMessage] [varchar](100) NULL,
CONSTRAINT [PK_AfterParse_CA_Events] PRIMARY KEY CLUSTERED
(
[EventID] ASC,
[MessageID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
这是我拥有的所有专栏。我想检查LSCI_DateOfRecord,CFI,RecordDate,EffectiveDate,DueBillRdmDate,PaymentDate,CUSIP,Symbol2和ExDividendDate。如果列中缺少数据(null),我想在ErrorMessage列中显示列名。
我已经为LSCI_DateOfRecord编写了一个简单的查询,但是当有多列缺少数据时,我不知道如何编写错误消息。
如果LSCI_DateOfRecord和DueBillRdmDate都为null,我希望ErrorMessage看起来像'缺少LSCI_DateOfRecord DueBillRdmDate'。
我的代码:
--build the ErrorMessage for AfterParse_CA_Events
declare @errorMessge varchar(1000)
select case
when ace.LSCI_DateOfRecord IS NULL then ' LSCI_RecordDate'
--when ace.DueBillRdmDate IS null then ' DueBillRdmDate'
else 'good'
end as ErrorMessage
,*
from AfterParse_CA_Events ace
任何人都可以帮助我。
答案 0 :(得分:1)
你正确地做了,你只需要连接它们。除非您对插入进行了检查,否则该列不会保留在您的数据库中。也就是说,对于触发器或您用于插入数据的内容,您必须检查插入的值,或者执行后续更新。
df = DataFrame(col1 = [1,2,3], col2 = ['a','b','c'])
df[:a] = 1:size(df, 1)
df[:a] = convert(DataArrays.DataArray{Float64,1},df[:a])
[df[i,:a] = NA for i in 1:size(df, 1) ]
或更新......
select
*,
ErrorColumn =
case when ace.LSCI_DateOfRecord IS NULL then 'LSCI_RecordDate' else '' end
+
case when ace.DueBillRdmDate IS NULL then 'DueBillRdmDate ' else '' end
+
...
from AfterParse_CA_Events ace
这里重要的一点是update t
set t.ErrorColumn = <case statement from above>
from AfterParse_CA_Events t
。我之所以这样做,是因为默认情况下,其他内容为else ''
和NULL
。例如:
NULL + <anything> = NULL