How to concatenate two Data?

2

How to concatenate two dates of type DateTime , one of which may have its value equal to NULL , I'm trying as follows;

DECLARE @DATA1 DATETIME = GETDATE(), @DATA2 DATETIME    
select  Convert(nvarchar(50),@DATA1 , 121) +'|'+ Convert(nvarchar(50), @DATA2, 121) 

But this returns null , when in fact I wanted the value of GETDATE () + something like empty or null.     

asked by anonymous 25.07.2016 / 15:17

2 answers

8

So, I tried with ISNULL ()

Here it worked:

DECLARE @DATA1 DATETIME = GETDATE(), @DATA2 DATETIME    
select  Convert(nvarchar(50),@DATA1 , 121) +'|'+ isnull(Convert(nvarchar(50), @DATA2, 121),'')
    
25.07.2016 / 15:54
3
DECLARE @DATA1 DATETIME, @DATA2 DATETIME;
SET @DATA1 = getdate()
SET @DATA2 = null
SELECT  CASE WHEN (@DATA1 IS NULL) THEN '' ELSE Convert(nvarchar(50),@DATA1 , 121) END +'|'+ CASE WHEN (@DATA2 is null) THEN '' ELSE Convert(nvarchar(50), @DATA2, 121) END
    
25.07.2016 / 15:53