我需要将数据从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}
答案 0 :(得分: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], ''),
coalesce9[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}
答案 1 :(得分:0)
在MS SQL SERVER中,如果您专门针对空值,则可以使用isnull函数。
isnull(column,'')