-1

我需要将数据从 SQL 表推送到 JDE 中的中间表。我遇到了 NULLS 没有作为空白传递的问题。如何将任何 NULL 值替换为 JDE 中的空白。

这是我更新我的 SQLDB 的声明:

Insert into AP_InvoiceHeader
(DocID,[Vendor Name],[Vendor No],[Invoice Number],[Invoice Date],[PO Number],[Invoice Amount],MVRUploadDate,DocName)

values ({sys DocID},'{doc Vendor Name}','{doc Vendor No}','{doc Invoice Number}','{doc Invoice Date}','{doc PO Number}','{doc Invoice Amount}',GETDATE(),(select DocName from document where Docid={sys DocID}))

使用此语句,如果没有要传递的值,它将在 SQL 中显示为 NULL。将 NULL 转换为空白到我的 SQLDB 会更好还是应该在我更新中间表时完成?

这是我的语句,它从我的 SQLDB 中选择并将其插入到中间 JDE 表中。我知道我想做什么,但是我不知道怎么写。我想说,如果[PO Number]=NULL将其更改为空白。有没有办法可以检查任何 NULLS 并用空白替换所有 NULLS?

 INSERT INTO [MyJDE_VENDOR].[PS_DEV].[TESTDTA].[F55METAA] ([MVMLNM],[MVAN8],[MVVR01],[MVVINV],[MVDIVJ],[MVAG],[MVTRDJ],[MVRMK3],[MV55MV],[MVUMEMO1])

    SELECT [Vendor Name],[Vendor No],[PO Number],[Invoice Number],cast('1'+ RIGHT(CAST(YEAR(cast([Invoice Date] as date)) AS CHAR(4)),2) + RIGHT('000' + CAST(DATEPART(dy, cast([Invoice Date] as date)) AS varchar(3)),3) as int) as [Invoice Date],[Invoice Amount]*100,cast('1'+ RIGHT(CAST(YEAR(cast([MVRUploadDate] as date)) AS CHAR(4)),2) + RIGHT('000' + CAST(DATEPART(dy, cast([MVRUploadDate] as date)) AS varchar(3)),3) as int) as [MVRUploadDate],[ProcessedFlag],[DocID],[DocName]

    FROM [MyDataBase].[dbo].[AP_InvoiceHeader] WHERE DocID ={sys DocID}
4

2 回答 2

2

标准 SQL 函数是coalesce(). 您希望将其用于哪些字段有点不清楚:

INSERT INTO [MyJDE_VENDOR].[PS_DEV].[TESTDTA].[F55METAA] ([MVMLNM],[MVAN8],[MVVR01],[MVVINV],[MVDIVJ],[MVAG],[MVTRDJ],[MVRMK3],[MV55MV],[MVUMEMO1])

SELECT coalesce([Vendor Name], ''),
       coalesce([Vendor No], ''), 
       coalesce([PO Number], ''),
       coalesce([Invoice Number], '')
       coalesce(cast('1'+ RIGHT(CAST(YEAR(cast([Invoice Date] as date)) AS CHAR(4)),2) + RIGHT('000' + CAST(DATEPART(dy, cast([Invoice Date] as date)) AS varchar(3)),3) as int) as [Invoice Date],[Invoice Amount]*100,cast('1'+ RIGHT(CAST(YEAR(cast([MVRUploadDate] as date)) AS CHAR(4)),2) + RIGHT('000' + CAST(DATEPART(dy, cast([MVRUploadDate] as date)) AS varchar(3)),3) as int) , '') as [MVRUploadDate],
       coalesce([ProcessedFlag], ''), 
       coalesce([DocID], ''), 
       coalesce([DocName], '')
FROM [MyDataBase].[dbo].[AP_InvoiceHeader]
WHERE DocID ={sys DocID}
于 2013-06-26T01:38:33.020 回答
0

在 MS SQL SERVER 中,如果您专门针对空值,则可以使用 isnull 函数。

isnull(column,'')
于 2013-06-26T03:14:30.450 回答